

- CONFIGURE POSTGRESQL UNIX SOCKET HOW TO
- CONFIGURE POSTGRESQL UNIX SOCKET PASSWORD
- CONFIGURE POSTGRESQL UNIX SOCKET WINDOWS
Use the port option with the listen_addresses option to control the interface where the port will be listening. The default port number is 5432but you can change it as required. The port option sets the PostgreSQL server port number that will be used when listening for TCP/ IP connections.


service postgresql restart Setting or changing the TCP port Restart the server for the changes to take effect. unix_socket_directory= /var/run/postgresql/ Remove or comment (#) the line to disable socket access. Specify a filesystem directory path, usually /var/run/postgresql/ and the socket will be created when the server next starts. The unix_socket_directory option indicates the filesystem path to the location of the directory you’d like to hold your socket. vi /etc/postgresql/9.5/main/nf Configuring local socket use (Linux/ Unix only) I’m using Linux for this example, but adjust the following steps to suit your environment.
CONFIGURE POSTGRESQL UNIX SOCKET WINDOWS
On Windows it’s usually C:\Program Files\PostgreSQL\9.5\data but again, you’ll have to take the version into account. In Linux you can use the following command to find the file: locate nfĪs you can see, the server version is included in the file path so you’ll need to check that before trying to open it. PostgreSQL Server can be configured to use a local socket, TCP connections or both.īe editing the nf file for the following sections however the location of the file is different depending on OS and PostgreSQL version. It incurs a small penalty over a local socket and therefore slightly higher latencies and is limited by the network bandwidth available. In larger or highly available systems this may not be possible.Ī TCP connection is the only option of connecting to your PostgreSQL database server from a remote machine. This comes with the limitation that it can only be used if the application accessing the database is on the same machine. In addition to a TCP listening port, PostgreSQL will also a local socket if the server is running in a Linux/ Unix environment. A local socket is the prefered method of connecting to a database as it removes much of the overhead of creating a TCP connection and transferring data. You should be prompted for a password, which only if you enter correctly, you will gain access.The default TCP port for PostgreSQL is usually 5432, however this can easily be changed in the nf configuration file, which is the main configuration file for the database server. To check that everything went correctly, try to make a connection to your local server by using your servers IP as below: psql -U postgres -h Now restart PostgreSQL for the changes to take effect. and add the following line: listen_addresses = '*' You can add multiple lines for multiple CIDRs. If you can swap out 0.0.0.0/0 for a more exact IP/CIDR of the servers that you wish to connect, that would be much better. Sudo vim /etc/postgresql/9.*/main/pg_hba.conf
CONFIGURE POSTGRESQL UNIX SOCKET PASSWORD
If you haven't set a password for your user already (above), do that now.Įdit the pg_hba.conf file and add the following line to allow connections from anywhere on the internet.
CONFIGURE POSTGRESQL UNIX SOCKET HOW TO
The steps below will show you how to configure your server to accept remote connections using a password for authentication. # "local" is for Unix domain socket connections onlyīy default, your server will not accept remote connections. Sudo vim /etc/postgresql/$VERSION/main/pg_hba.confĬhange from: # "local" is for Unix domain socket connections only If you wish to enable passwords, and be able to log in locally with users that exist in PostgreSQL that don't exist as users in your linux system, then change your pg_hba.conf file from trust or peer to md5 as shown below: VERSION=* sudo /etc/init.d/postgresql restartĬonnecting from a local socket on the server itself doesn't require a password and requires you to be logged in as that user. Restart the service for the changes to take effect. Ctrl + D also works and is easier to remember, but clashes with byobu. Use the command \q to exit out of the CLI utility. In the CLI, enter: ALTER USER postgres with encrypted password 'my_password'
