Skip to content

Commit

Permalink
Merge pull request #18 from Dakotah312/master
Browse files Browse the repository at this point in the history
Adding host name support
  • Loading branch information
keithf4 authored May 26, 2022
2 parents 1fcf19d + 4c7acb9 commit b9d49e6
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
1.5.0
-- Added new configuration column to support host/service names allowing for dynamic ip addresses to be used.
-- host and hostaddr reference: https://www.postgresql.org/docs/current/libpq-connect.html

1.4.1
-- Fix incorrect data type usage in the add_job() function (Github Issue #14).

Expand Down
6 changes: 3 additions & 3 deletions META.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "pg_jobmon",
"abstract": "Job logging and monitoring extension",
"version": "1.4.1",
"version": "1.5.0",
"maintainer": [
"Robert Treat <[email protected]>",
"Keith Fiske <[email protected]>"
Expand All @@ -19,9 +19,9 @@
},
"provides": {
"pg_jobmon": {
"file": "sql/pg_jobmon--1.4.1.sql",
"file": "sql/pg_jobmon--1.5.0.sql",
"docfile": "doc/pg_jobmon.md",
"version": "1.4.1",
"version": "1.5.0",
"abstract": "Job logging and monitoring extension"
}
},
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ If you're running PostgreSQL on a port other than the default (5432), you can al

Be aware that the dblink_mapping_jobmon table can only have a single row, so if you're using a custom host, role or different port, you will need to enter those values within a single row. None of the columns are required, so just use the ones you need for your setup.

INSERT INTO jobmon.dblink_mapping_jobmon (host,username, pwd, port) VALUES ('host','rolename', 'rolepassword', '5999');
INSERT INTO jobmon.dblink_mapping_jobmon (host, hostaddr, username, pwd, port) VALUES ('host', 'hostaddr', 'rolename', 'rolepassword', '5999');

UPGRADE
-------
Expand Down
2 changes: 1 addition & 1 deletion pg_jobmon.control
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
default_version = '1.4.1'
default_version = '1.5.0'
comment = 'Extension for logging and monitoring functions in PostgreSQL'
requires = dblink
relocatable = false
9 changes: 7 additions & 2 deletions sql/functions/auth.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ DECLARE
v_password text;
v_username text;
v_host text;
v_hostaddr text;

BEGIN
-- Ensure only one row is returned. No rows is fine, but this was the only way to force one.
-- Trigger on table should enforce it as well, but extra check doesn't hurt.
BEGIN
SELECT host, username, port, pwd INTO STRICT v_host, v_username, v_port, v_password FROM @[email protected]_mapping_jobmon;
SELECT host, hostaddr, username, port, pwd INTO STRICT v_host, v_hostaddr, v_username, v_port, v_password FROM @[email protected]_mapping_jobmon;
EXCEPTION
WHEN NO_DATA_FOUND THEN
-- Do nothing
Expand All @@ -40,7 +41,11 @@ BEGIN
END IF;

IF v_host IS NOT NULL THEN
v_auth := v_auth || ' hostaddr='||v_host;
v_auth := v_auth || ' host='||v_host;
END IF;

IF v_hostaddr IS NOT NULL THEN
v_auth := v_auth || ' hostaddr='||v_hostaddr;
END IF;
RETURN v_auth;
END
Expand Down
3 changes: 2 additions & 1 deletion sql/tables/tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ CREATE TABLE dblink_mapping_jobmon (
username text,
port text,
pwd text,
host text
host text,
hostaddr text
);
SELECT pg_catalog.pg_extension_config_dump('dblink_mapping_jobmon', '');

Expand Down
55 changes: 55 additions & 0 deletions updates/pg_jobmon--1.4.1--1.5.0.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
-- Added new configuration column to support host/service names allowing for dynamic ip addresses to be used.


ALTER TABLE @[email protected]_mapping_jobmon ADD COLUMN hostaddr text;
UPDATE @[email protected]_mapping_jobmon SET hostaddr = host, host = NULL;

CREATE OR REPLACE FUNCTION auth() RETURNS text
LANGUAGE plpgsql STABLE
AS $$
DECLARE

v_auth text = '';
v_port text;
v_password text;
v_username text;
v_host text;
v_hostaddr text;

BEGIN
-- Ensure only one row is returned. No rows is fine, but this was the only way to force one.
-- Trigger on table should enforce it as well, but extra check doesn't hurt.
BEGIN
SELECT host, hostaddr, username, port, pwd INTO STRICT v_host, v_hostaddr, v_username, v_port, v_password FROM @[email protected]_mapping_jobmon;
EXCEPTION
WHEN NO_DATA_FOUND THEN
-- Do nothing
WHEN TOO_MANY_ROWS THEN
RAISE EXCEPTION 'dblink_mapping_jobmon table can only have a single entry';
END;


IF v_port IS NULL THEN
v_auth = 'dbname=' || current_database();
ELSE
v_auth := 'port='||v_port||' dbname=' || current_database();
END IF;

IF v_username IS NOT NULL THEN
v_auth := v_auth || ' user='||v_username;
END IF;

IF v_password IS NOT NULL THEN
v_auth := v_auth || ' password='||v_password;
END IF;

IF v_host IS NOT NULL THEN
v_auth := v_auth || ' host='||v_host;
END IF;

IF v_hostaddr IS NOT NULL THEN
v_auth := v_auth || ' hostaddr='||v_hostaddr;
END IF;
RETURN v_auth;
END
$$;

0 comments on commit b9d49e6

Please sign in to comment.