- PostgreSQL database default location on Linux
- How to Install PostgreSQL on Ubuntu [Setup & Configurations Covered]
- Install PostgreSQL on Ubuntu
- Connect to PostgreSQL & Change Password
- PostgreSQL Remote Connection Configuration
- Test PostgreSQL Remote Connection
- Important PostgreSQL Server Configurations
- PostgreSQL Server Installation FAQs
- Does PostgreSQL have a default database?
- What is the location of postgresql.conf file?
- What is the location of pg_hba.conf file?
- Conclusion
- Install PostgreSQL 10 on Arch Linux
- Where is Pg_hba conf in Linux?
- Where is Postgres located?
- How do I connect to PostgreSQL?
- What is the password for Postgres?
- How do I start postgresql in manjaro?
- How run postgresql on manjaro?
- How do I start postgresql on Linux?
- Where is postgresql conf centos7?
- How do I get Postgres to accept remote connections?
PostgreSQL database default location on Linux
The «directory where postgresql will keep all databases» (and configuration) is called «data directory» and corresponds to what PostgreSQL calls (a little confusingly) a «database cluster», which is not related to distributed computing, it just means a group of databases and related objects managed by a PostgreSQL server.
The location of the data directory depends on the distribution. If you install from source, the default is /usr/local/pgsql/data :
In file system terms, a database cluster will be a single directory under which all data will be stored. We call this the data directory or data area. It is completely up to you where you choose to store your data. There is no default, although locations such as /usr/local/pgsql/data or /var/lib/pgsql/data are popular. (ref)
Besides, an instance of a running PostgreSQL server is associated to one cluster; the location of its data directory can be passed to the server daemon («postmaster» or «postgres») in the -D command line option, or by the PGDATA environment variable (usually in the scope of the running user, typically postgres ). You can usually see the running server with something like this:
[root@server1 ~]# ps auxw | grep postgres | grep -- -D postgres 1535 0.0 0.1 39768 1584 ? S May17 0:23 /usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data
Note that it is possible, though not very frequent, to run two instances of the same PostgreSQL server (same binaries, different processes) that serve different «clusters» (data directories). Of course, each instance would listen on its own TCP/IP port.
How to Install PostgreSQL on Ubuntu [Setup & Configurations Covered]
This guide will teach you how to install PostgreSQL on Ubuntu and change its key configurations.
PostgreSQL is one of the best open source object-relational database systems. Whether you are a developer, sysadmin, or DevOps engineer, it is essential to know the basic setup and configurations involved in a PostgreSQL setup.
As per the latest StackOverflow developer survey, 40.42% of developers use PostgreSQL as a database.
Install PostgreSQL on Ubuntu
It is always better to download the latest version available in the official PostgreSQL Ubuntu repository.
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add - sudo apt-get update
Install the latest version of PostgreSQL
sudo apt-get -y install postgresql
If you want to install a specific version of PostgreSQL, you can search for the available versions from here and use the version with the install command as shown below.
sudo apt-get -y install postgresql-12
Lets validate PostgreSQL by checking the service status.
sudo systemctl status postgresql
Connect to PostgreSQL & Change Password
You can connect to the PostgreSQL server using the psql client
When you install PostgreSQL, the psql client also gets installed.
Execute the following command to connect to the server.
Let’s check the version of PostgreSQL using the following command.
Now, we have to change the postgres user’s password so that we can allow remote PostgreSQL connection using password authentication.
Execute the following query to set a password. Replace myPassword with a password of your choice.
ALTER USER postgres PASSWORD 'myPassword';
PostgreSQL Remote Connection Configuration
By default, the PostgreSQL server is accessible only on the loopback interface (127.0.0.1) on port 5432 and through the Unix socket. Therefore, you can only connect to the PostgreSQL server from within the Ubuntu server where PostgreSQL is installed .
You can verify it by listing all the TCP connections using the ss Linux networking command.
To enable remote connection to PostgreSQL, we need to allow it in the postgresql.conf file.
For Ubuntu systems, postgresql.conf is located in /etc/postgresql/14/main/ location. 14 is the version number.
If you are using a different PostgreSQL version, change it accordingly.
Or you can use the following find command to locate the file.
sudo find / -name "postgresql.conf"
Open the file postgresql.conf file.
sudo vi /etc/postgresql/14/main/postgresql.conf
Under CONNECTIONS AND AUTHENTICATION section you will find the following commented parameter.
#listen_addresses = 'localhost'
Replace it with the following and save the file. With this configuration, we are enabling PostgreSQL server connections to accept connections from all IP addresses.
To apply the change, restart the PostgreSQL service.
sudo systemctl restart postgresql
Now, if you list all the TCP connections, you can see the PostgreSQL service listening on all interfaces, as shown below.
We have allowed only connections on all interfaces. However, If you try to connect to PostgreSQL from a remote machine, you will get the following error because you need to enable client connections to all the Databases and users.
psql: error: connection to server at "", port 5432 failed: FATAL: no pg_hba.conf entry for host "", user "postgres", database "postgres", SSL encryption connection to server at "", port 5432 failed: FATAL: no pg_hba.conf entry for host "", user "postgres", database "postgres", no encryption
To allow client connections to all databases, you need to edit the pg_hba.conf file.
Open pg_hba.conf file.
sudo vi /etc/postgresql/14/main/pg_hba.conf
Add the following line to the end of the file.
Test PostgreSQL Remote Connection
Now, let’s try connecting PostgreSQL from a remote machine.
First, install the PostgreSQL client on the system you are trying to connect to the PostgreSQL server.
sudo apt-get install postgresql-client
brew install libpq brew link --force libpq
Once the client is installed, execute the following psql command to connect to the PostgreSQL remotely. Replace 192.168.5.5 with your PostgreSQL server IP. When it prompts for a password, enter the password we generated during the initial configuration.
psql -h 192.168.5.5 -U postgres
Important PostgreSQL Server Configurations
The following table contains important PostgreSQL configurations.
Config | Details |
---|---|
PostgreSQL default port | 5432 |
Default user | postgres |
Config files location ( postgresql.conf & pg_hba.conf ) | /etc/postgresql/postgresql.conf /etc/postgresql/pg_hba.conf |
Default database | postgres |
Default data directory | /var/lib/postgresql/ |
PostgreSQL Server Installation FAQs
Does PostgreSQL have a default database?
Yes. When you install PostgreSQL, a default database named Postgres gets created. It contains user information, utilities, and third-party applications.
What is the location of postgresql.conf file?
The postgresql.conf file is located at the /etc/postgresql/ location. For example, if you are using PostgreSQL 14, the absolute url of postgresql.conf will be /etc/postgresql/14/main/postgresql.conf .
What is the location of pg_hba.conf file?
The pg_hba.conf file is located at the /etc/postgresql/ location. For example, if you are using PostgreSQL 14, the absolute url of pg_hba.conf would be /etc/postgresql/14/main/pg_hba.conf .
Conclusion
This guide looked at the steps to install PostgreSQL on a Ubuntu server.
For the Redhat server, Checkout the PostgreSQL installation on Redhat
For the Amazon Linux server, Checkout the PostgreSQL installation on Amazon Linux
As a DevOps engineer, it is essential to know the basic configurations involved in a Database.
If you are starting your DevOps engineer journey, look at my comprehensive guide to becoming a DevOps engineer.
Bibin Wilson
Bibin Wilson is a cloud and DevOps consultant with over 10 years of IT experience. He has extensive hands-on experience with public cloud platforms, cloud hosting, Kubernetes and OpenShift deployments in production. He has authored over 300 tech tutorials, providing valuable insights to the DevOps community. His courses on techiescamp.com offer practical guidance and real-world examples for professionals aiming to excel in cloud, DevOps, and infrastructure automation.
Install PostgreSQL 10 on Arch Linux
PostgreSQL configuration files are stored in the /etc/postgresql//main directory. For example, if you install PostgreSQL 12, the configuration files are stored in the /etc/postgresql/12/main directory.
Where is Pg_hba conf in Linux?
The standard location is pg_hba. conf within the data_directory of the database (which could be in /home , /var/lib/pgsql , /var/lib/postgresql/[version]/ , /opt/postgres/ , etc etc etc) but users and packagers can put it wherever they like. Unfortunately.
Where is Postgres located?
PostgreSQL Changing Database Location. When using Fedora 12, the default location for PostgreSQL to store its database is /var/lib/pgsql/data .
How do I connect to PostgreSQL?
- Download and install a PostgreSQL server. .
- Add the PostgreSQL bin directory path to the PATH environmental variable. .
- Open the psql command-line tool: .
- Run a CREATE DATABASE command to create a new database. .
- Connect to the new database using the command: \c databaseName.
- Run the postgres.
What is the password for Postgres?
The first question many ask is, “What is the default password for the user postgres?” The answer is easy… there isn’t a default password. The default authentication mode for PostgreSQL is set to ident.
How do I start postgresql in manjaro?
- Step 1 — Install the dependencies. sudo pacman -S yay yay postgresql pgadmin4. .
- Step 2 — Setup postgres service. .
- Step 3 — Setup password. .
- Step 4 — Setup connection security. .
- Step 6 — PgAdmin.
How run postgresql on manjaro?
- Enable snaps on Manjaro Linux and install postgresql. .
- sudo pacman -S snapd.
- sudo systemctl enable —now snapd.socket.
- sudo ln -s /var/lib/snapd/snap /snap.
- To install postgresql, simply use the following command:
How do I start postgresql on Linux?
- Initialize the server by running the command: sudo service postgresql-9.3 initdb.
- Start the server by running the command: sudo service postgresql-9.3 start.
Where is postgresql conf centos7?
You can add the -contrib package along with the installation command to add additional functionalities and features to your PostgreSQL. The configuration file of PostgreSQL database gets stored in the ‘/var/lib/pgsql/12/data/postgresql. conf’.
How do I get Postgres to accept remote connections?
- Connect to the PostgreSQL server via SSH.
- Get location of postgresql.conf file by executing the command (it should be something like /var/lib/pgsql/data/postgresql.conf ): .
- Open postgresql.conf file and add the following line to the end: .
- Get the location of pg_hba.conf file:
Find
What is Find command in Linux with example?How do I find the command line in Linux?How do you use Find command to search a file in Linux?How do I list.
Debug
Bash shell offers debugging options which can be turn on or off using the set command:set -x : Display commands and their arguments as they are execut.
Public
Where do I put SSH key in Debian?How do I add a key to SSH?How do I find my SSH public key?What is SSH add command?Where do I put SSH key in Debian?Th.
Latest news, practical advice, detailed reviews and guides. We have everything about the Linux operating system