32
32
-- version() returns a long human readable string, hence we split from others SELECTs eg.
33
33
-- PostgreSQL 12.3 (Debian 12.3-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
34
34
SELECT
35
- version(),
36
- current_setting(' server_version' ) AS " server_version" ,
37
- current_setting(' server_version_num' ) AS " server_version_num" ;
35
+ version(),
36
+ current_setting(' server_version' ) AS " server_version" ,
37
+ current_setting(' server_version_num' ) AS " server_version_num" ;
38
38
39
39
-- ========================================================================== --
40
40
-- S e r v e r D e t a i l s
@@ -44,18 +44,18 @@ SELECT
44
44
-- \pset title 'PostgreSQL Server Details'
45
45
46
46
SELECT
47
- pg_postmaster_start_time(),
48
- pg_conf_load_time(),
49
- current_setting(' logging_collector' ) AS " logging_collector" ,
50
- current_setting(' log_destination' ) AS " log_destination" ,
51
- -- not available in Postgres 9
52
- -- doesn't work because it still checks if pg_current_logfile() is valid and neither eval or execute seem to work around this
53
- -- CASE WHEN current_setting('server_version_num')::int > 100000 THEN pg_current_logfile() ELSE NULL END as pg_current_logfile
54
- pg_current_logfile()
55
- -- current_setting('log_directory') AS "log_directory", -- log
56
- -- current_setting('log_filename') AS "log_filename", -- postgresql-%Y-%m-%d_%H%M%S.log
57
- -- not available on Postgres 10
58
- -- pg_jit_available()
47
+ pg_postmaster_start_time(),
48
+ pg_conf_load_time(),
49
+ current_setting(' logging_collector' ) AS " logging_collector" ,
50
+ current_setting(' log_destination' ) AS " log_destination" ,
51
+ -- not available in Postgres 9
52
+ -- doesn't work because it still checks if pg_current_logfile() is valid and neither eval or execute seem to work around this
53
+ -- CASE WHEN current_setting('server_version_num')::int > 100000 THEN pg_current_logfile() ELSE NULL END as pg_current_logfile
54
+ pg_current_logfile()
55
+ -- current_setting('log_directory') AS "log_directory", -- log
56
+ -- current_setting('log_filename') AS "log_filename", -- postgresql-%Y-%m-%d_%H%M%S.log
57
+ -- not available on Postgres 10
58
+ -- pg_jit_available()
59
59
;
60
60
61
61
-- SELECT pg_reload_conf(), pg_rotate_logfile();
@@ -87,18 +87,18 @@ SELECT
87
87
-- \pset title 'Config Files'
88
88
89
89
SELECT
90
- current_setting(' config_file' ) AS " config_file" ,
91
- current_setting(' hba_file' ) AS " hba_file" ,
92
- current_setting(' ident_file' ) AS " ident_file" ;
90
+ current_setting(' config_file' ) AS " config_file" ,
91
+ current_setting(' hba_file' ) AS " hba_file" ,
92
+ current_setting(' ident_file' ) AS " ident_file" ;
93
93
94
94
\echo
95
95
-- \pset title 'PostgreSQL Data Directory & Unix Sockets'
96
96
97
97
SELECT
98
- current_setting(' data_directory' ) AS " data_directory" ,
99
- current_setting(' unix_socket_directories' ) AS " unix_socket_directories" ,
100
- current_setting(' unix_socket_permissions' ) AS " unix_socket_permissions" ,
101
- current_setting(' unix_socket_group' ) AS " unix_socket_group" ;
98
+ current_setting(' data_directory' ) AS " data_directory" ,
99
+ current_setting(' unix_socket_directories' ) AS " unix_socket_directories" ,
100
+ current_setting(' unix_socket_permissions' ) AS " unix_socket_permissions" ,
101
+ current_setting(' unix_socket_group' ) AS " unix_socket_group" ;
102
102
103
103
-- ========================================================================== --
104
104
-- B u f f e r s & C o n n e c t i o n s
@@ -108,13 +108,13 @@ SELECT
108
108
-- \pset title 'Buffers & Connections'
109
109
110
110
SELECT
111
- current_setting(' shared_buffers' ) AS " shared_buffers" ,
112
- current_setting(' work_mem' ) AS " work_mem" ,
113
- current_setting(' max_connections' ) AS " max_connections" ,
114
- current_setting(' max_files_per_process' ) AS " max_files_per_process" , -- should be less than ulimit nofiles to avoid “Too many open files” failures
115
- current_setting(' track_activities' ) AS " track_activities" , -- for pg_stat / pg_statio family of system views that are used in many other adjacent scripts
116
- current_setting(' track_counts' ) AS " track_counts" , -- needed for the autovacuum daemon
117
- current_setting(' password_encryption' ) AS " password_encryption" ;
111
+ current_setting(' shared_buffers' ) AS " shared_buffers" ,
112
+ current_setting(' work_mem' ) AS " work_mem" ,
113
+ current_setting(' max_connections' ) AS " max_connections" ,
114
+ current_setting(' max_files_per_process' ) AS " max_files_per_process" , -- should be less than ulimit nofiles to avoid “Too many open files” failures
115
+ current_setting(' track_activities' ) AS " track_activities" , -- for pg_stat / pg_statio family of system views that are used in many other adjacent scripts
116
+ current_setting(' track_counts' ) AS " track_counts" , -- needed for the autovacuum daemon
117
+ current_setting(' password_encryption' ) AS " password_encryption" ;
118
118
119
119
120
120
-- ========================================================================== --
@@ -126,12 +126,12 @@ SELECT
126
126
127
127
-- in SQL the following have special syntax and should be called without parens: current_catalog, current_role, current_schema, current_user, session_user
128
128
SELECT
129
- current_user , -- aka user, current_role - this is the effective user for permission checking
130
- session_user , -- connection user before superuser SET SESSION AUTHORIZATION
131
- current_schema,
132
- current_catalog, -- SQL standard, same as current_database()
133
- pg_backend_pid(),
134
- current_query();
129
+ current_user , -- aka user, current_role - this is the effective user for permission checking
130
+ session_user , -- connection user before superuser SET SESSION AUTHORIZATION
131
+ current_schema,
132
+ current_catalog, -- SQL standard, same as current_database()
133
+ pg_backend_pid(),
134
+ current_query();
135
135
136
136
\echo
137
137
-- \pset title 'Schema search list'
@@ -147,16 +147,16 @@ SELECT current_schemas(true) AS "current_schemas(true) - auto-searched schemas";
147
147
-- \pset title 'Backup & Recovery'
148
148
149
149
SELECT
150
- pg_is_in_backup(),
151
- pg_is_in_recovery(),
152
- pg_backup_start_time(),
153
- ' see postgres_recovery.sql for more info' AS " info" ;
154
- -- use postgres_recovery.sql instead of having a big blank table distracting us here
155
- -- the following recovery control functions can only be executed during recovery - to get just the above use postgres_funcs.sql
156
- -- ( CASE WHEN pg_is_in_recovery() THEN pg_is_wal_replay_paused() END) AS "pg_is_wal_replay_paused()",
157
- -- ( CASE WHEN pg_is_in_recovery() THEN pg_last_wal_receive_lsn() END) AS "pg_last_wal_receive_lsn()",
158
- -- ( CASE WHEN pg_is_in_recovery() THEN pg_last_wal_replay_lsn() END) AS "pg_last_wal_replay_lsn()",
159
- -- ( CASE WHEN pg_is_in_recovery() THEN pg_last_xact_replay_timestamp() END) AS "pg_last_xact_replay_timestamp()"
150
+ pg_is_in_backup(),
151
+ pg_is_in_recovery(),
152
+ pg_backup_start_time(),
153
+ ' see postgres_recovery.sql for more info' AS " info" ;
154
+ -- use postgres_recovery.sql instead of having a big blank table distracting us here
155
+ -- the following recovery control functions can only be executed during recovery - to get just the above use postgres_funcs.sql
156
+ -- ( CASE WHEN pg_is_in_recovery() THEN pg_is_wal_replay_paused() END) AS "pg_is_wal_replay_paused()",
157
+ -- ( CASE WHEN pg_is_in_recovery() THEN pg_last_wal_receive_lsn() END) AS "pg_last_wal_receive_lsn()",
158
+ -- ( CASE WHEN pg_is_in_recovery() THEN pg_last_wal_replay_lsn() END) AS "pg_last_wal_replay_lsn()",
159
+ -- ( CASE WHEN pg_is_in_recovery() THEN pg_last_xact_replay_timestamp() END) AS "pg_last_xact_replay_timestamp()"
160
160
161
161
-- SELECT
162
162
-- pg_ls_logdir(),
@@ -173,10 +173,10 @@ SELECT
173
173
-- \pset title 'Networking'
174
174
175
175
SELECT
176
- inet_client_addr(),
177
- inet_client_addr(),
178
- inet_server_addr(),
179
- inet_server_port();
176
+ inet_client_addr(),
177
+ inet_client_addr(),
178
+ inet_server_addr(),
179
+ inet_server_port();
180
180
181
181
-- causes 0 rows when mixed with other select funcs
182
182
-- SELECT pg_listening_channels();
@@ -193,23 +193,23 @@ SELECT
193
193
-- \pset title 'Date & Time'
194
194
195
195
SELECT
196
- -- current timestamps even inside transactions/functions
197
- now(),
198
- timeofday(), -- human string timestamp with timezone
199
-
200
- -- at start of current transaction for consistency, includes +offset timezone
201
- current_timestamp (2 ) AS " current_timestamp(2)" , -- secs precision of 2 decimal places, includes +offset timezone
202
- current_date ,
203
- current_time (1 ) AS " current_time(1)" , -- includes +offset timezone
204
- localtime,
205
- localtimestamp(1 ) AS " localtimestamp(1)" ,
206
-
207
- -- provide current timestamps even inside transactions/functions
208
- -- now()
209
- -- timeofday(), -- human string timestamp with timezone
210
- clock_timestamp(), -- current date + time (changes throughout function)
211
- statement_timestamp(),
212
- transaction_timestamp() -- same as CURRENT_TIMESTAMP
196
+ -- current timestamps even inside transactions/functions
197
+ now(),
198
+ timeofday(), -- human string timestamp with timezone
199
+
200
+ -- at start of current transaction for consistency, includes +offset timezone
201
+ current_timestamp (2 ) AS " current_timestamp(2)" , -- secs precision of 2 decimal places, includes +offset timezone
202
+ current_date ,
203
+ current_time (1 ) AS " current_time(1)" , -- includes +offset timezone
204
+ localtime,
205
+ localtimestamp(1 ) AS " localtimestamp(1)" ,
206
+
207
+ -- provide current timestamps even inside transactions/functions
208
+ -- now()
209
+ -- timeofday(), -- human string timestamp with timezone
210
+ clock_timestamp(), -- current date + time (changes throughout function)
211
+ statement_timestamp(),
212
+ transaction_timestamp() -- same as CURRENT_TIMESTAMP
213
213
;
214
214
215
215
-- \pset title
0 commit comments