pgbouncer
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
pgbouncer [2024/08/27 14:49] – created jbi | pgbouncer [2024/08/30 11:35] (current) – jbi | ||
---|---|---|---|
Line 5: | Line 5: | ||
< | < | ||
- | SELECT usename, passwd | + | psql -Atq -U postgres -d postgres -c "SELECT |
</ | </ | ||
- | insert encrypted password into / | + | insert encrypted password into **/ |
+ | ie: | ||
" | " | ||
- | In /etc/pgbouncer/pgbouncer.ini | + | Per database setup. |
- | set | + | < |
+ | REVOKE ALL PRIVILEGES ON SCHEMA public FROM pgbouncer; | ||
+ | CREATE SCHEMA IF NOT EXISTS pgbouncer; | ||
+ | REVOKE ALL PRIVILEGES ON SCHEMA pgbouncer FROM pgbouncer; | ||
+ | GRANT USAGE ON SCHEMA pgbouncer TO pgbouncer; | ||
- | - auth_type = scram-sha-256 | + | CREATE OR REPLACE FUNCTION |
- | - auth_file = /etc/pgbouncer/userlist.txt | + | RETURNS TABLE(username TEXT, password TEXT) AS |
- | - auth_query = SELECT | + | $$ |
- | - auth_user=pgbouncer | + | |
+ | FROM pg_catalog.pg_authid | ||
+ | WHERE | ||
+ | -- disable line below if superusers (postgres) should connect to | ||
+ | NOT pg_authid.rolsuper AND | ||
+ | NOT pg_authid.rolreplication AND | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | ) AND | ||
+ | | ||
+ | $$ | ||
+ | LANGUAGE SQL STABLE SECURITY DEFINER; | ||
+ | REVOKE ALL ON FUNCTION pgbouncer.get_auth(username TEXT) FROM PUBLIC, pgbouncer; | ||
+ | GRANT EXECUTE ON FUNCTION pgbouncer.get_auth(username TEXT) TO pgbouncer; | ||
- | When it is working, change auth_query to something more secure, ie from pgbouncer.org | ||
- | < | ||
- | CREATE OR REPLACE FUNCTION pgbouncer.user_lookup(in i_username text, out uname text, out phash text) | ||
- | RETURNS record AS $$ | ||
- | BEGIN | ||
- | SELECT usename, passwd FROM pg_catalog.pg_shadow | ||
- | WHERE usename = i_username INTO uname, phash; | ||
- | RETURN; | ||
- | END; | ||
- | $$ LANGUAGE plpgsql SECURITY DEFINER; | ||
- | REVOKE ALL ON FUNCTION pgbouncer.user_lookup(text) FROM public, pgbouncer; | ||
- | GRANT EXECUTE ON FUNCTION pgbouncer.user_lookup(text) TO pgbouncer; | ||
</ | </ | ||
+ | Minimum / | ||
+ | < | ||
+ | [databases] | ||
+ | * = host=10.97.97.97 port=5432 auth_user=pgbouncer | ||
+ | [users] | ||
+ | [pgbouncer] | ||
+ | logfile = / | ||
+ | pidfile = / | ||
+ | listen_addr = * | ||
+ | listen_port = 6432 | ||
+ | unix_socket_dir = / | ||
+ | auth_type = md5 | ||
+ | auth_file = / | ||
+ | auth_query = SELECT username, password from pgbouncer.get_auth($1) | ||
+ | admin_users = pgbouncer | ||
+ | stats_users = pgbouncer | ||
+ | </ | ||
+ | pg_hba.conf at the cluster | ||
+ | < | ||
+ | .. | ||
+ | .. | ||
+ | host all | ||
+ | </ | ||
pgbouncer.1724762974.txt.gz · Last modified: 2024/08/27 14:49 by jbi