PostgreSQL
 SQL >> Database >  >> RDS >> PostgreSQL

Leggere impostazioni PostgreSQL come max_connections a runtime

La via diretta è il comando SHOW:

SHOW max_connections;

Restituisce il valore attualmente in vigore, che non deve per forza coincidere con postgresql.conf, perché PostgreSQL offre più modi per impostare i parametri a runtime. Per riportare la sessione al default configurato:

RESET max_connections;

Non basta però per max_connections: il manuale specifica che può essere impostato solo all’avvio del server. Per vedere tutto:

SHOW ALL;

C’è anche la vista pg_settings, un’interfaccia alternativa a SHOW/SET che espone anche min/max e altre informazioni. La query che risponde direttamente alla domanda è:

SELECT * FROM pg_settings WHERE name = 'max_connections';

Infine current_setting(), comoda perché annidabile nel DML:

SELECT current_setting('max_connections');

Per gli script è spesso preferibile pg_settings: SHOW restituisce una sola colonna con etichetta scomoda, mentre pg_settings offre setting, unit, source e pending_restart come colonne filtrabili.