-
Notifications
You must be signed in to change notification settings - Fork 1
/
.psqlrc
52 lines (47 loc) · 1.48 KB
/
.psqlrc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/* helpful ad hoc commands for debug purposes */
\set pid 'SELECT pg_backend_pid();'
\set gdb 'SELECT pg_backend_pid() \\g |pg_debug'
/* the query for building the prompt */
select (
with
shown_settings(id, name, fmt, hidden_value) as (
values
/* put your lines here */
(1, 'primary_or_replica', '%s', NULL),
(2, 'neon.pageserver_connstring', '@neon', NULL),
(3, 'port', 'port=%s', 5432)
),
settings(name, value) as (
/* global settings */
select name, setting from pg_catalog.pg_settings
/* put your custom setting providers here */
union select
'primary_or_replica',
case
when pg_catalog.pg_is_in_recovery() then '@R'
else null /* don't show anything on primary */
end
),
config(id, kvp) as (
select
shown_settings.id,
pg_catalog.format(shown_settings.fmt, settings.value)
from settings join shown_settings using(name)
where settings.value is distinct from shown_settings.hidden_value :: text
)
select '[' || string_agg(kvp, ', ' order by id) || ']' from config
) as prompt_hints
\gset
/* the prompt itself */
\set PROMPT1 '%/%:prompt_hints:=# '
/* query execution time */
\timing on
/* set a better pager */
\set QUIET 1
\pset linestyle unicode
\pset border 2
\pset null ∅
\set less '\\setenv PAGER less'
\set pspg '\\setenv PAGER \'pspg -s 0\''
:pspg
-- vim: ft=sql