Skip to main content

PostgreSQL Interface

ClickHouse supports the PostgreSQL wire protocol, which allows you to use Postgres clients to connect to ClickHouse. In a sense, ClickHouse can pretend to be a PostgreSQL instance - allowing you to connect a PostgreSQL client application to ClickHouse that is not already directy supported by ClickHouse (for example, Amazon Redshift).

To enable the PostgreSQL wire protocol, add the postgresql_port setting to your server's configuration file. For example, you could define the port in a new XML file in your config.d folder:


Startup your ClickHouse server and look for a log message similar to the following that mentions Listening for PostgreSQL compatibility protocol:

{} <Information> Application: Listening for PostgreSQL compatibility protocol:

Connect psql to ClickHouse

The following command demonstrates how to connect the PostgreSQL client psql to ClickHouse:

psql -p [port] -h [hostname] -U [username] [database_name]

For example:

psql -p 9005 -h -U alice default

The psql client requires a login with a password, so you will not be able connect using the default user with no password. Either assign a password to the default user, or login as a different user.

The psql client prompts for the password:

Password for user alice:
psql (14.2, server
WARNING: psql major version 14, server major version 22.
Some psql features might not work.
Type "help" for help.


And that's it! You now have a PostgreSQL client connected to ClickHouse, and all commands and queries are executed on ClickHouse.


The PostgreSQL protocol currently only supports plain-text passwords.

Using SSL

If you have SSL/TLS configured on your ClickHouse instance, then postgresql_port will use the same settings (the port is shared for both secure and unsecure clients).

Each client has their own method of how to connect using SSL. The following command demonstrates how to pass in the certificates and key to securely connect psql to ClickHouse:

psql "port=9005 host= user=alice dbname=default sslcert=/path/to/certificate.pem sslkey=/path/to/key.pem sslrootcert=/path/to/rootcert.pem sslmode=verify-ca"

View the PostgreSQL docs for more details on their SSL settings.

Original article