PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
settings.h
Go to the documentation of this file.
1/*
2 * psql - the PostgreSQL interactive terminal
3 *
4 * Copyright (c) 2000-2025, PostgreSQL Global Development Group
5 *
6 * src/bin/psql/settings.h
7 */
8#ifndef SETTINGS_H
9#define SETTINGS_H
10
11#include "fe_utils/print.h"
12#include "variables.h"
13
14#define DEFAULT_CSV_FIELD_SEP ','
15#define DEFAULT_FIELD_SEP "|"
16#define DEFAULT_RECORD_SEP "\n"
17
18#if defined(WIN32) || defined(__CYGWIN__)
19#define DEFAULT_EDITOR "notepad.exe"
20/* no DEFAULT_EDITOR_LINENUMBER_ARG for Notepad */
21#else
22#define DEFAULT_EDITOR "vi"
23#define DEFAULT_EDITOR_LINENUMBER_ARG "+"
24#endif
25
26#define DEFAULT_PROMPT1 "%/%R%x%# "
27#define DEFAULT_PROMPT2 "%/%R%x%# "
28#define DEFAULT_PROMPT3 ">> "
29
30#define DEFAULT_WATCH_INTERVAL "2"
31/*
32 * Limit the max default setting to a value which should be safe for the
33 * itimer call, yet large enough to cover all realistic usecases.
34 */
35#define DEFAULT_WATCH_INTERVAL_MAX (1000*1000)
36/*
37 * Note: these enums should generally be chosen so that zero corresponds
38 * to the default behavior.
39 */
40
41typedef enum
42{
47} PSQL_ECHO;
48
49typedef enum
50{
55
56typedef enum
57{
62
63typedef enum
64{
70
71typedef enum
72{
85
86typedef enum
87{
93
95{
99};
100
101typedef struct _psqlSettings
102{
103 PGconn *db; /* connection to backend */
104 int encoding; /* client_encoding */
105 FILE *queryFout; /* where to send the query results */
106 bool queryFoutPipe; /* queryFout is from a popen() */
107
108 FILE *copyStream; /* Stream to read/write for \copy command */
109
110 PGresult *last_error_result; /* most recent error result, if any */
111
112 printQueryOpt popt; /* The active print format settings */
113
114 char *gfname; /* one-shot file output argument for \g */
115 printQueryOpt *gsavepopt; /* if not null, saved print format settings */
116
117 char *gset_prefix; /* one-shot prefix argument for \gset */
118 bool gdesc_flag; /* one-shot request to describe query result */
119 bool gexec_flag; /* one-shot request to execute query result */
120 PSQL_SEND_MODE send_mode; /* one-shot request to send query with normal
121 * or extended query protocol */
122 int bind_nparams; /* number of parameters */
123 char **bind_params; /* parameters for extended query protocol call */
124 char *stmtName; /* prepared statement name used for extended
125 * query protocol commands */
126 int piped_commands; /* number of piped commands */
127 int piped_syncs; /* number of piped syncs */
128 int available_results; /* number of results available to get */
129 int requested_results; /* number of requested results, including
130 * sync messages. Used to read a limited
131 * subset of the available_results. */
132 bool crosstab_flag; /* one-shot request to crosstab result */
133 char *ctv_args[4]; /* \crosstabview arguments */
134
135 bool notty; /* stdin or stdout is not a tty (as determined
136 * on startup) */
137 enum trivalue getPassword; /* prompt the user for a username and password */
138 FILE *cur_cmd_source; /* describe the status of the current main
139 * loop */
141 int sversion; /* backend server version */
142 const char *progname; /* in case you renamed psql */
143 char *inputfile; /* file being currently processed, if any */
144 uint64 lineno; /* also for error reporting */
145 uint64 stmt_lineno; /* line number inside the current statement */
146
147 bool timing; /* enable timing of all queries */
148
149 FILE *logfile; /* session log file handle */
150
151 VariableSpace vars; /* "shell variable" repository */
152
153 /*
154 * If we get a connection failure, the now-unusable PGconn is stashed here
155 * until we can successfully reconnect. Never attempt to do anything with
156 * this PGconn except extract parameters for a \connect attempt.
157 */
158 PGconn *dead_conn; /* previous connection to backend */
159
160 /*
161 * The remaining fields are set by assign hooks associated with entries in
162 * "vars". They should not be set directly except by those hook
163 * functions.
164 */
167 bool quiet;
181 const char *prompt1;
182 const char *prompt2;
183 const char *prompt3;
184 PGVerbosity verbosity; /* current error verbosity level */
186 PGContextVisibility show_context; /* current context display level */
188
189extern PsqlSettings pset;
190
191
192#ifndef EXIT_SUCCESS
193#define EXIT_SUCCESS 0
194#endif
195
196#ifndef EXIT_FAILURE
197#define EXIT_FAILURE 1
198#endif
199
200#define EXIT_BADCONN 2
201
202#define EXIT_USER 3
203
204#endif
uint64_t uint64
Definition: c.h:503
PGContextVisibility
Definition: libpq-fe.h:163
PGVerbosity
Definition: libpq-fe.h:155
PSQL_ERROR_ROLLBACK
Definition: settings.h:57
@ PSQL_ERROR_ROLLBACK_INTERACTIVE
Definition: settings.h:59
@ PSQL_ERROR_ROLLBACK_ON
Definition: settings.h:60
@ PSQL_ERROR_ROLLBACK_OFF
Definition: settings.h:58
HistControl
Definition: settings.h:87
@ hctl_ignoredups
Definition: settings.h:90
@ hctl_ignoreboth
Definition: settings.h:91
@ hctl_none
Definition: settings.h:88
@ hctl_ignorespace
Definition: settings.h:89
PSQL_ECHO
Definition: settings.h:42
@ PSQL_ECHO_ALL
Definition: settings.h:46
@ PSQL_ECHO_ERRORS
Definition: settings.h:45
@ PSQL_ECHO_NONE
Definition: settings.h:43
@ PSQL_ECHO_QUERIES
Definition: settings.h:44
struct _psqlSettings PsqlSettings
PSQL_ECHO_HIDDEN
Definition: settings.h:50
@ PSQL_ECHO_HIDDEN_NOEXEC
Definition: settings.h:53
@ PSQL_ECHO_HIDDEN_OFF
Definition: settings.h:51
@ PSQL_ECHO_HIDDEN_ON
Definition: settings.h:52
@ TRI_YES
Definition: settings.h:98
@ TRI_DEFAULT
Definition: settings.h:96
@ TRI_NO
Definition: settings.h:97
PsqlSettings pset
Definition: startup.c:32
PSQL_SEND_MODE
Definition: settings.h:72
@ PSQL_SEND_PIPELINE_SYNC
Definition: settings.h:78
@ PSQL_SEND_FLUSH
Definition: settings.h:81
@ PSQL_SEND_FLUSH_REQUEST
Definition: settings.h:82
@ PSQL_SEND_START_PIPELINE_MODE
Definition: settings.h:79
@ PSQL_SEND_QUERY
Definition: settings.h:73
@ PSQL_SEND_EXTENDED_QUERY_PARAMS
Definition: settings.h:76
@ PSQL_SEND_EXTENDED_PARSE
Definition: settings.h:75
@ PSQL_SEND_END_PIPELINE_MODE
Definition: settings.h:80
@ PSQL_SEND_GET_RESULTS
Definition: settings.h:83
@ PSQL_SEND_EXTENDED_CLOSE
Definition: settings.h:74
@ PSQL_SEND_EXTENDED_QUERY_PREPARED
Definition: settings.h:77
PSQL_COMP_CASE
Definition: settings.h:64
@ PSQL_COMP_CASE_PRESERVE_LOWER
Definition: settings.h:66
@ PSQL_COMP_CASE_LOWER
Definition: settings.h:68
@ PSQL_COMP_CASE_PRESERVE_UPPER
Definition: settings.h:65
@ PSQL_COMP_CASE_UPPER
Definition: settings.h:67
uint64 lineno
Definition: settings.h:144
printQueryOpt popt
Definition: settings.h:112
double watch_interval
Definition: settings.h:175
char * gset_prefix
Definition: settings.h:117
PSQL_ERROR_ROLLBACK on_error_rollback
Definition: settings.h:178
bool hide_tableam
Definition: settings.h:171
VariableSpace vars
Definition: settings.h:151
PSQL_COMP_CASE comp_case
Definition: settings.h:179
char * inputfile
Definition: settings.h:143
PGVerbosity verbosity
Definition: settings.h:184
bool hide_compression
Definition: settings.h:170
FILE * logfile
Definition: settings.h:149
char * stmtName
Definition: settings.h:124
bool on_error_stop
Definition: settings.h:166
PGconn * dead_conn
Definition: settings.h:158
bool autocommit
Definition: settings.h:165
char * ctv_args[4]
Definition: settings.h:133
int available_results
Definition: settings.h:128
PGresult * last_error_result
Definition: settings.h:110
int piped_syncs
Definition: settings.h:127
bool show_all_results
Definition: settings.h:185
const char * prompt2
Definition: settings.h:182
const char * prompt3
Definition: settings.h:183
FILE * copyStream
Definition: settings.h:108
int piped_commands
Definition: settings.h:126
char ** bind_params
Definition: settings.h:123
PGconn * db
Definition: settings.h:103
FILE * queryFout
Definition: settings.h:105
PSQL_SEND_MODE send_mode
Definition: settings.h:120
bool queryFoutPipe
Definition: settings.h:106
PSQL_ECHO echo
Definition: settings.h:176
bool singlestep
Definition: settings.h:169
enum trivalue getPassword
Definition: settings.h:137
uint64 stmt_lineno
Definition: settings.h:145
bool singleline
Definition: settings.h:168
int requested_results
Definition: settings.h:129
PGContextVisibility show_context
Definition: settings.h:186
const char * prompt1
Definition: settings.h:181
PSQL_ECHO_HIDDEN echo_hidden
Definition: settings.h:177
printQueryOpt * gsavepopt
Definition: settings.h:115
char * gfname
Definition: settings.h:114
int fetch_count
Definition: settings.h:172
bool cur_cmd_interactive
Definition: settings.h:140
bool gexec_flag
Definition: settings.h:119
bool crosstab_flag
Definition: settings.h:132
FILE * cur_cmd_source
Definition: settings.h:138
HistControl histcontrol
Definition: settings.h:180
const char * progname
Definition: settings.h:142
bool gdesc_flag
Definition: settings.h:118
int bind_nparams
Definition: settings.h:122
trivalue
Definition: vacuumlo.c:35