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