19

I need to specify sslmode=allow when using psql to connect to my PostgreSQL DB, like: psql sslmode=allow -h localhost -p 5432 otherwise I get server does not support SSL, but SSL was required

I tried specifying the same option to pg_dump but it doesn't recognize the option.

How do I specify sslmode to pg_dump?

qwertzguy
  • 15,699
  • 9
  • 63
  • 66

2 Answers2

35

You need to use the environment variable PGSSLMODE like this:

PGSSLMODE=allow pg_dump -h localhost -p 5432

qwertzguy
  • 15,699
  • 9
  • 63
  • 66
0

see https://dba.stackexchange.com/a/227805

pg_dump "port=<port> host=<host> user=<user> dbname=<db> sslcert=<cert> sslkey=<key> sslrootcert=<ca.crt> sslmode=allow" -f <file>      
ps_ttf
  • 1,096
  • 7
  • 15
  • I believe that requires the postgres server to support ssl – qwertzguy Apr 28 '22 at 16:05
  • isn't it a base requirement for any kind of answer to enable ssl in pg_dump to work? – ps_ttf Apr 29 '22 at 21:24
  • The premise of the question was about connecting to a server that doesn't support ssl. See my answer for how to do that with pg_dump – qwertzguy May 01 '22 at 01:35
  • I see what you mean, so I changed my answer to `sslmode=allow`. My point is that there is a way to do it without setting env vars. Am I wrong? – ps_ttf May 02 '22 at 13:00
  • I see, didn't know that you could put connection options in a string as first arg. So I guess your answer could be simplified to: `pg_dump "port=5432 host=localhost sslmode=allow"` – qwertzguy May 03 '22 at 19:25