On 04/16/2018 10:18 AM, Keith Fiske wrote:
>
>
> On Mon, Apr 16, 2018 at 12:21 PM, Tom Lane <tgl@sss.pgh.pa.us
> <mailto:tgl@sss.pgh.pa.us>> wrote:
>
>
> So playing around with the "client_encoding" configuration option in
> postgresql.conf. According to the docs, setting this should set the
> default encoding for any client that connects, right?
>
> https://www.postgresql.org/docs/10/static/runtime-config-client.html#GUC-CLIENT-ENCODING
> <https://www.postgresql.org/docs/10/static/runtime-config-client.html#GUC-CLIENT-ENCODING>
>
> That description also seems misleading in saying that the default client
> encoding is what the database encoding is as well. At least as far as
> psql is concerned, right? I've tried setting that value in
> postgresql.conf but psql keeps setting it to UTF8 when I connect to the
> SQL_ASCII database unless I then specifically run "set client_encoding =
> 'SQL_ASCII';"
Realized that while my previous suggestion of setting PGCLIENTENCODING
to 'SQL_ASCII' would work it would also affect libpq programs beside psql.
For a finer grained approach set \encoding 'SQL_ASCII' in a .psqlrc file.:
https://www.postgresql.org/docs/10/static/app-psql.html
"Files
psqlrc and ~/.psqlrc
Unless it is passed an -X option, psql attempts to read and execute
commands from the system-wide startup file (psqlrc) and then the user's
personal startup file (~/.psqlrc), after connecting to the database but
before accepting normal commands. These files can be used to set up the
client and/or the server to taste, typically with \set and SET commands.
The system-wide startup file is named psqlrc and is sought in the
installation's “system configuration” directory, which is most reliably
identified by running pg_config --sysconfdir. By default this directory
will be ../etc/ relative to the directory containing the PostgreSQL
executables. The name of this directory can be set explicitly via the
PGSYSCONFDIR environment variable.
The user's personal startup file is named .psqlrc and is sought in
the invoking user's home directory. On Windows, which lacks such a
concept, the personal startup file is named
%APPDATA%\postgresql\psqlrc.conf. The location of the user's startup
file can be set explicitly via the PSQLRC environment variable.
Both the system-wide startup file and the user's personal startup
file can be made psql-version-specific by appending a dash and the
PostgreSQL major or minor release number to the file name, for example
~/.psqlrc-9.2 or ~/.psqlrc-9.2.5. The most specific version-matching
file will be read in preference to a non-version-specific file.
"
>
> --
> Keith Fiske
> Senior Database Engineer
> Crunchy Data - http://crunchydata.com
--
Adrian Klaver
adrian.klaver@aklaver.com