Ask Your Question
1

How to configure SSL in PostgreSQL?

asked 2023-05-16 07:47:29 +0000

lakamha gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2023-05-16 08:12:02 +0000

djk gravatar image

To configure SSL in PostgreSQL, follow these steps:

  1. Enable SSL in the PostgreSQL server by setting the following parameters in the postgresql.conf file: ssl = on sslcertfile = '/path/to/server.crt' sslkeyfile = '/path/to/server.key' sslcafile = '/path/to/root.crt'

Note: These parameters will point to the SSL certificate files you have created for PostgreSQL. You may need to replace the filepaths with your own server configuration.

  1. Restart the PostgreSQL server for these changes to take effect.

  2. Create an SSL user for PostgreSQL with the following command: CREATE USER ssluser WITH PASSWORD 'password' SSL;

  3. To test the SSL connection, connect to PostgreSQL with the ssluser and specify the SSL mode with the following command: psql -h hostname -U ssluser -d dbname -p port -W sslmode=require

Note: Replace the hostname, dbname and port with your PostgreSQL server configuration. You will be prompted for the ssluser's password.

  1. If the SSL connection is successful, you should see a message indicating that the SSL connection was established.

  2. Finally, revoke the privileges of the SSL user to prevent it from accessing PostgreSQL without SSL: REVOKE CONNECT ON DATABASE dbname FROM PUBLIC; REVOKE SELECT ON pgcatalog.pgstat_ssl FROM PUBLIC;

Note: Replace dbname with the name of your PostgreSQL database.

That's it! You have successfully configured SSL in PostgreSQL.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-05-16 07:47:29 +0000

Seen: 13 times

Last updated: May 16 '23