1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-01-18 04:58:51 +02:00

Set client_encoding to UTF8 on PostgreSQL connect.

This is the only non-ASCII character encoding we have tested so make sure that's all we get from PostgreSQL.
This commit is contained in:
David Steele 2020-01-21 18:42:22 -07:00
parent 1706c599bd
commit 600a51815f
3 changed files with 18 additions and 0 deletions

View File

@ -207,6 +207,9 @@ dbOpen(Db *this)
// but this is an extra level protection.
dbExec(this, STRDEF("set search_path = 'pg_catalog'"));
// Set client encoding to UTF8. This is the only encoding (other than ASCII) that we can safely work with.
dbExec(this, STRDEF("set client_encoding = 'UTF8'"));
// Query the version and data_directory
VariantList *row = dbQueryRow(
this,

View File

@ -45,6 +45,15 @@ Macros for defining groups of functions that implement various queries and comma
{.session = sessionParam, .function = HRNPQ_CONNECTDB, .param = "[\"" connectParam "\"]"}, \
{.session = sessionParam, .function = HRNPQ_STATUS, .resultInt = CONNECTION_OK}
#define HRNPQ_MACRO_SET_CLIENT_ENCODING(sessionParam) \
{.session = sessionParam, .function = HRNPQ_SENDQUERY, .param = "[\"set client_encoding = 'UTF8'\"]", .resultInt = 1}, \
{.session = sessionParam, .function = HRNPQ_CONSUMEINPUT}, \
{.session = sessionParam, .function = HRNPQ_ISBUSY}, \
{.session = sessionParam, .function = HRNPQ_GETRESULT}, \
{.session = sessionParam, .function = HRNPQ_RESULTSTATUS, .resultInt = PGRES_COMMAND_OK}, \
{.session = sessionParam, .function = HRNPQ_CLEAR}, \
{.session = sessionParam, .function = HRNPQ_GETRESULT, .resultNull = true}
#define HRNPQ_MACRO_SET_SEARCH_PATH(sessionParam) \
{.session = sessionParam, .function = HRNPQ_SENDQUERY, .param = "[\"set search_path = 'pg_catalog'\"]", .resultInt = 1}, \
{.session = sessionParam, .function = HRNPQ_CONSUMEINPUT}, \
@ -486,11 +495,13 @@ Macros to simplify dbOpen() for specific database versions
#define HRNPQ_MACRO_OPEN_LE_91(sessionParam, connectParam, pgVersion, pgPathParam, archiveMode, archiveCommand) \
HRNPQ_MACRO_OPEN(sessionParam, connectParam), \
HRNPQ_MACRO_SET_SEARCH_PATH(sessionParam), \
HRNPQ_MACRO_SET_CLIENT_ENCODING(sessionParam), \
HRNPQ_MACRO_VALIDATE_QUERY(sessionParam, pgVersion, pgPathParam, archiveMode, archiveCommand)
#define HRNPQ_MACRO_OPEN_GE_92(sessionParam, connectParam, pgVersion, pgPathParam, standbyParam, archiveMode, archiveCommand) \
HRNPQ_MACRO_OPEN(sessionParam, connectParam), \
HRNPQ_MACRO_SET_SEARCH_PATH(sessionParam), \
HRNPQ_MACRO_SET_CLIENT_ENCODING(sessionParam), \
HRNPQ_MACRO_VALIDATE_QUERY(sessionParam, pgVersion, pgPathParam, archiveMode, archiveCommand), \
HRNPQ_MACRO_SET_APPLICATION_NAME(sessionParam), \
HRNPQ_MACRO_IS_STANDBY_QUERY(sessionParam, standbyParam)

View File

@ -81,11 +81,13 @@ testRun(void)
{
HRNPQ_MACRO_OPEN(1, "dbname='postgres' port=5432"),
HRNPQ_MACRO_SET_SEARCH_PATH(1),
HRNPQ_MACRO_SET_CLIENT_ENCODING(1),
HRNPQ_MACRO_VALIDATE_QUERY(1, PG_VERSION_84, "/pgdata", NULL, NULL),
HRNPQ_MACRO_CLOSE(1),
HRNPQ_MACRO_OPEN(1, "dbname='postgres' port=5432"),
HRNPQ_MACRO_SET_SEARCH_PATH(1),
HRNPQ_MACRO_SET_CLIENT_ENCODING(1),
HRNPQ_MACRO_VALIDATE_QUERY(1, PG_VERSION_84, "/pgdata", NULL, NULL),
HRNPQ_MACRO_WAL_SWITCH(1, "xlog", "000000030000000200000003"),
HRNPQ_MACRO_CLOSE(1),
@ -470,6 +472,7 @@ testRun(void)
{
HRNPQ_MACRO_OPEN(1, "dbname='postgres' port=5432 user='bob'"),
HRNPQ_MACRO_SET_SEARCH_PATH(1),
HRNPQ_MACRO_SET_CLIENT_ENCODING(1),
HRNPQ_MACRO_VALIDATE_QUERY(1, PG_VERSION_94, "/pgdata", NULL, NULL),
HRNPQ_MACRO_SET_APPLICATION_NAME(1),
HRNPQ_MACRO_IS_STANDBY_QUERY(1, true),
@ -486,6 +489,7 @@ testRun(void)
{
HRNPQ_MACRO_OPEN(1, "dbname='postgres' port=5432 user='bob'"),
HRNPQ_MACRO_SET_SEARCH_PATH(1),
HRNPQ_MACRO_SET_CLIENT_ENCODING(1),
HRNPQ_MACRO_VALIDATE_QUERY(1, PG_VERSION_94, "/pgdata", NULL, NULL),
HRNPQ_MACRO_SET_APPLICATION_NAME(1),
HRNPQ_MACRO_IS_STANDBY_QUERY(1, false),