This post explains how to install PostgreSQL on CentOS Linux (Redhat family), Ubuntu Linux (Debian family), and the Windows Platform.
Linux Platform
On the Linux Platform, there are 3 installation methods.
Installing with a Package Manager
Use a Package Manager that resolves dependencies between installed Packages automatically, such as yum (Yellowdog Updater, Modified) on CentOS or apt (Advanced Packaging Tool) on Ubuntu. To use these Package Managers, the server needs internet access to reach the PostgreSQL Package Repository. This method installs the latest Minor version of the PostgreSQL Major version.
Installing individual Packages
You can download the PostgreSQL installation Packages yourself and install them with rpm (RedHat Package Manager) on CentOS or dpkg (Debian Package) on Ubuntu. Once the PostgreSQL Packages are ready, you can install even without internet access and choose the PostgreSQL version. However, you must resolve dependencies between Packages yourself.
Installing from PostgreSQL Source Files
You can download the Source Files from the PostgreSQL community (postgresql.org) and Build the files for installing PostgreSQL from them. As long as the Libraries for the Build are ready, you can choose any PostgreSQL version regardless of dependencies.
💡 On Redhat-family Linux such as CentOS, the distribution policy means the PostgreSQL Database is not initialized and the service does not start automatically, so you must initialize the Database and enable service autostart manually.
On Debian-family Linux such as Ubuntu, on the other hand, installing PostgreSQL initializes the PostgreSQL Database and starts the service automatically, so you do not need to run initdb manually.
Windows Platform
On the Windows Platform, there are 2 installation methods.
Installing with the installer
You can install the PostgreSQL version you want in a few clicks through the installer GUI.
Installing from a Binary File (Zip Archive)
This is similar to Source Files on the Linux Platform, but no Build is needed for the installation files. You simply unzip the Binary File and run initialization to start using PostgreSQL.
The table below summarizes what to note on first installation for each Platform.
ㅤ
Linux
ㅤ
ㅤ
ㅤ
ㅤ
Window
ㅤ
ㅤ
yum
apt
rpm
dpkg
Source File
Installer
Binary File
Installation Package
Repository
Repository
Repository
Prepared separately
Repository
Prepared separately
Prepared separately
Prepared separately
Prepared separately
Dependencies
Resolved automatically
Resolved automatically
Resolved by user
Resolved by user
Resolved by user
Resolved by user
Resolved by user
Installed version
Latest Minor per Major
Latest Minor per Major
Selectable
Selectable
Selectable
Selectable
Selectable
Engine path
Not changeable
Not changeable
Not changeable
Changeable
Changeable
Changeable
Changeable
Data Directory
Changeable
Not changeable
Changeable
Changeable
Changeable
Changeable
Changeable
Notes
Internet connection required
Internet connection required
ㅤ
ㅤ
ㅤ
ㅤ
ㅤ
When PostgreSQL is installed, the Engine Directory and Data Directory go to default paths, which differ by Platform as shown in the table below. VERSION in the Directory paths means the Major version.
Directories in a default installation
ㅤ
CentOS
(Redhat family)
Ubuntu
(Debian family)
Windows
Engine
/usr/pgsql-{VERSION}
/usr/lib/postgresql/{VERSION}
C:\Program Files\PostgreSQL\{VERSION}
Data
/var/lib/pgsql/{VERSION}/data
/var/lib/postgresql/{VERSION}/main
C:\Program Files\PostgreSQL\{VERSION}\data
Configuration
/var/lib/pgsql/{VERSION}/data
/etc/postgresql/{VERSION}/main
C:\Program Files\PostgreSQL\{VERSION}\data
Service name
postgresql-{VERSION}
postgresql@{VERSION}-main
postgresql-x64-{VERSION}
From here on, we explain how to install PostgreSQL on each Platform. The versions used are as follows, and Linux is split into the Redhat family and the Debian family.
OS Version: CentOS 7.9, Ubuntu 22.04, Windows 10
DB Version: PostgreSQL 14.5
Install PostgreSQL on Linux (CentOS - yum)
On Redhat-family Linux, you can install PostgreSQL with yum from the PostgreSQL yum Repository. The PostgreSQL yum Repository is available only for RedHat Enterprise Linux, Rocky Linux, CentOS(6 and 7 only), Oracle Linux, and Fedora. When installing with yum, several Packages are installed because of dependencies between Packages.
Packages installed as dependencies
Package name
Description
postgresql14-libs
Shared libraries required by all PostgreSQL Client programs
postgresql14
PostgreSQL Client programs and libraries
postgresql14-server
Programs needed to create and run a PostgreSQL Server
libpq.so.5
PostgreSQL C language Client library
Additional PostgreSQL Packages you can install
Package name
Description
postgresql14-contrib
Source and binaries distributed with PostgreSQL
postgresql14-devel
PostgreSQL development header files and libraries
postgresql14-docs
Additional documentation for PostgreSQL
postgresql14-llvmjit
JIT (Just-in-time) compilation support for PostgreSQL
postgresql14-odbc
PostgreSQL ODBC driver
postgresql14-plperl
Perl procedural language for PostgreSQL (Procedural Language Perl)
postgresql14-plpython3
Python3 procedural language for PostgreSQL (Procedural Language Python3)
postgresql14-pltcl
Tcl procedural language for PostgreSQL (Procedural Language Tcl)
postgresql14-tcl
Tcl Client library for PostgreSQL
postgresql14-test
Test suite distributed with PostgreSQL
1. PostgreSQL yum Repository Install
Output
2. PostgreSQL Install
Output
3. PostgreSQL Initialization
Using the default Data Directory
Output
Using a custom Data Directory
1) Create the Data Directory
💡 initdb can create the Data Directory inside a directory owned by the postgres account, but not in a directory it does not own, where it fails with a Permission denied error.
2) PostgreSQL Initialization
Output
3) Edit the PostgreSQL Service file
4. Start PostgreSQL
💡 ※ Controlling PostgreSQL with systemctl
systemctl{ enable | start | stop | status }{ PostgreSQL-Service-Name }
5. Connect to PostgreSQL and verify
Output
Install PostgreSQL on Linux (CentOS - rpm)
You can download the rpm files for installing PostgreSQL on a machine (PC) with internet access, then move them to the Server where you want to install PostgreSQL. When installing with rpm, watch out for dependencies between Packages. Only the file preparation differs from installing with yum.
1. PostgreSQL Package Download
You can download the Packages for the OS versions listed in the table below from the PostgreSQL yum Repository (yum.postgresql.org/packages), or download them with yum on a Server with internet access.
Output
Package name
Description
postgresql14-libs
Shared libraries required by all PostgreSQL Client programs
postgresql14
PostgreSQL Client programs and libraries
postgresql14-server
Programs needed to create and run a PostgreSQL Server
2. PostgreSQL Install
Because of dependencies between Packages, install them in the order postgresql14-libs → postgresql14 → postgresql14-server.
Output
3. PostgreSQL Initialization
Using the default Data Directory
Output
Using a custom Data Directory
1) Create the Data Directory
💡 initdb can create the Data Directory inside a directory owned by the postgres account, but not in a directory it does not own, where it fails with a Permission denied error.
2) PostgreSQL Initialization
Output
3) Edit the PostgreSQL Service file
4. Start PostgreSQL
💡※ Controlling PostgreSQL with systemctl
systemctl { enable | start | stop | status }{ PostgreSQL-Service-Name }
5. Connect to PostgreSQL and verify
Output
Install PostgreSQL on Linux (Ubuntu - apt)
On Debian-family Linux, you can install PostgreSQL with apt from the PostgreSQL apt Repository.
Packages installed as dependencies
Package name
Description
libpq5
PostgreSQL C language Client library
libcommon-sense-perl
Modules for Perl programs
libjson-perl
Module for manipulating JSON-format Data
pgdg-keyring
apt.postgresql.org Keyring
postgresql-client-common
PostgreSQL Client version manager
postgresql-client-14
Includes PostgreSQL Client programs and administration programs
libtypes-serialiser-perl
Module that provides simple data types for common serialization formats
libjson-xs-perl
Module for manipulating JSON::XS-format data, used as an alternative to XML
libllvm14
JIT (Just-in-time) compilation support for PostgreSQL
postgresql-common
PostgreSQL Database Cluster Manager
postgresql-14
Programs needed to create and run a PostgreSQL Server
libsensors-config
lm-sensor configuration files (temperature, voltage, fan speed, etc.)
libsensors5
Library for reading lm-sensor data (temperature, voltage, fans, etc.)
ssl-cert
OepnSSL
sysstat
System performance tools for Linux
1. PostgreSQL apt Repository Install
Output
2. PostgreSQL Install
Output
💡 On Ubuntu, the PostgreSQL Install step also runs initdb and registers the service, so the PostgreSQL Initialization and PostgreSQL service start steps are not needed. To change the Data Directory, you must change the path after installation and restart.
3. Connect to PostgreSQL and verify
Output
Install PostgreSQL on Linux (Ubuntu - dpkg)
As with installing via rpm, you can install PostgreSQL from Debian-family .deb Package files with dpkg. Watch out for dependencies between Packages. Only the file preparation differs from installing with apt.
1. PostgreSQL Package Download
You can download the Packages for the OS versions listed in the table below from the PostgreSQL apt Repository (apt.postgresql.org/pub/repos/apt/pool/main/p/), or download them with apt on a Server with internet access.
Output
Package name
Description
pgdg-keyring
apt.postgresql.org Keyring
postgresql-client-common
PostgreSQL Client version manager
postgresql-client-14
Includes PostgreSQL Client programs and administration programs
postgresql-common
PostgreSQL Database Cluster Manager
postgresql-14
Programs needed to create and run a PostgreSQL Server
2. PostgreSQL Install
Install the Packages in the order listed below, following their dependencies.
Output
3. PostgreSQL Initialization
Using the default Data Directory
On Ubuntu, installing PostgreSQL also runs initdb and registers the service. The initdb application is created only when the postgresql-14 Package is installed, which is what lets you initialize the PostgreSQL Database. The postgresql-14 Package requires the libllvm14 Library, so install the libllvm14 Library Package first.
Output
If you install the postgresql-14 Package with the default PostgreSQL Configuration as above, the default Data Directory is used. The default Data Directory is /var/lib/postgresql/14/main.
Custom Data Directory
If you change the PostgreSQL Configuration as in the example below before installing the postgresql-14 Package, you can initialize the Database with a Data Directory of your choice.
Output
4. Connect to PostgreSQL and verify
Output
Install PostgreSQL on Linux (Source File)
You can install PostgreSQL by Building the installation files from Source Files. The OS Packages required for the Build, such as gcc, make, readline(optional), and zlib(optional), must be installed first.
1. PostgreSQL Source File Download
You can download Source Files for each PostgreSQL version from the PostgreSQL download center (www.postgresql.org/ftp/source/). The Source File used in the test is postgresql-14.5.tar.gz.
2. Create the PostgreSQL OS account
3. Create the PostgreSQL Engine Directory
4. Extract the PostgreSQL installation file
5. PostgreSQL Install Configure settings
The PostgreSQL Install Configure step Builds what is needed to install the PostgreSQL Server, and you can include the features you need at this stage. For example, to include JIT, add the --with-llvm option, and to include LZ4 compression, add the --with-lz4 option when Building the Install File. You can list configure options with configure --help.
OutputRelated errorsconfigure --help
6. Install the PostgreSQL Server
7. PostgreSQL Database Initialization
Output
8. Start PostgreSQL
Output
9. Connect to PostgreSQL and verify
Output
10. Register the PostgreSQL Service
1) Register the service
2) Control the service
Install PostgreSQL on Windows (Installer)
Installing PostgreSQL on Windows is very easy with the installer. The installer can install PostgreSQL Server and pgAdmin, and also StackBuilder, which you can use to download and install PostgreSQL tools and drivers. StackBuilder includes Management, Integration, Migration, Replication, Geospatial, and Connector tools.
Install PostgreSQL through the installer (GUI) with the steps below.
Step 1. Run the downloaded PostgreSQL 14.5 installation file
Step 2. Specify the PostgreSQL Engine installation path and click Next
This is the PostgreSQL Engine installation path. The default is C:\Program Files\PostgreSQL\{VERSION}.
Step 3. Select (or deselect) the components to install and click Next
PostgreSQL Server : includes the PostgreSQL Database Server
pgAdmin4 : includes the PostgreSQL GUI Management Tool
Stack Builder : includes Management, integration, Migration, Replication, Geospatial, and more
Command Line Tools : includes Command Line Interfaces such as psql, pg_dump, and pg_restore
Step 4. Specify the PostgreSQL Data Directory and click Next
This is the Data storage path. The default is C:\Program Files\PostgreSQL\{VERSION}\data.
Step 5. Set the password for postgres, the Database Superuser account, and click Next
Step 6. Specify the Port for the PostgreSQL Server and click Next
Step 7. Select the default Locale for the Database and click Next
This is the default language for PostgreSQL. The default is Default locale, which follows the OS setting.
Step 8. Review the settings from Step 2 to Step 7and click Next
Step 9. Click Next to run the installation
Step 10. Choose whether to launch Stack Builder and click Finish
3. Connect to PostgreSQL and verify
Check the connection and version of the installed PostgreSQL with a Client program such as pgAdmin or psql.
Install PostgreSQL on Windows (Binary File)
Installing PostgreSQL from a Binary File (Zip Archive) without the installer is similar to Source Files on the Linux Platform, but no Build is needed for the installation files. You simply unzip the Binary File and run initialization to start using PostgreSQL.
Install PostgreSQL in the order of the steps below.
Step 1. Unzip the downloaded Binary File
Step 2. Move the pgsql folder under the extracted folder to the location you want and rename it
Step 3. Create the folder to use as the PostgreSQL Data Directory
Step 4. Initialize (initdb) to set up the PostgreSQL Cluster
💡 "The code execution cannot proceed because VCRUNTIME140.dll was not found. Reinstalling the program may fix this problem."
This error occurs when the VC++ runtime library for Microsoft Visual Studio 2015 is missing. To fix it, download and install the Visual C++ Redistributable Package for Visual Studio 2015 from the Microsoft Download Center (https://www.microsoft.com/ko-kr/download/details.aspx?id=48145).
Step 5. Register and start the PostgreSQL service (run Command Prompt as administrator)
3. Connect to PostgreSQL and verify
Check the connection and version of the installed PostgreSQL with a Client program such as pgAdmin or psql.
Appendix 1. Changing configuration files for remote access
After installing PostgreSQL, remote access is disabled by default. In other words, you can connect only locally on the machine where the PostgreSQL Server is installed. To allow remote access, edit the PostgreSQL Configuration files and restart the service. The default locations of the Configuration Files are below and are described in the Install Overview.
CentOS : /var/lib/pgsql/{VERSION}/data
Ubuntu : /var/lib/postgresql/{VERSION}/main
Windows : C:\Program Files\PostgreSQL\{VERSION}\data
1. Open the firewall (Firewalld)
Open the Port used by the PostgreSQL Server in the firewall.
💡 See the PostgreSQL reference pg_hba.conf for details.
5. Restart PostgreSQL
Appendix 2. Preparing to use Extensions
This appendix explains how to install the pg_stat_statements and pgcrypto Extensions.
CentOS - Installing Extensions with a PostgreSQL installation
1. Install the PostgreSQL Contrib Package
** Installing the Contrib Package with yum
Output
** Installing the Contrib Package with rpm
Download the Contrib Package
Output
Install the Contrib Package
Output
2. Install the pg_stat_statements and pgcrypto Extensions
Output
3. Verify the Extension installation
Output
Ubuntu - Installing Extensions with a PostgreSQL installation
1. Install the PostgreSQL Contrib Package
** Installing the Contrib Package with apt
Output
** Installing the Contrib Package with dpkg
Download the Contrib Package
Output
Install the Contrib Package
Output
2. Install the pg_stat_statements and pgcrypto Extensions
Output
3. Verify the Extension installation
Output
Installing Extensions when PostgreSQL is installed from Source Files
The PostgreSQL Source Files include the Source Files for the Extensions that ship with PostgreSQL. The Extension Source Files are in the contrib directory of the directory where PostgreSQL is installed.
You can install Extensions using the Makefile. Each directory has its own Makefile. You can install all Extensions with the Makefile in the contrib directory, or install a single Extension with the Makefile in that Extension's directory.
This appendix explains how to install the pg_stat_statements and pgcrypto Extensions.
1. Prepare the pg_stat_statements Extension
Output
2. Prepare the pgcrypto Extension
Output
3. Install the pg_stat_statements and pgcrypto Extensions
Output
4. Verify the Extension installation
Output
Appendix 3. Installing Windows Stack Builder
If you check the Stack Builder option at the last step of the PostgreSQL installation, "Completing the PostgreSQL Setup Wizard", and finish, you can install the additional modules included in Stack Builder.
Modules you can install with Stack Builder
Category
Selectable items
Add-ons, tools, and Utilities
- EDB Language Pack
- pgAgent(64bit) for PostgreSQL
- pgBouncer
Database Drivers
- Npgsql
- pgJDBC
- psqlODBC (32bit/64bit)
Database Server
32bit/64bit PostgreSQL Server (latest Minor versions of 9.6-14)
Registration-required and trial products
(EnterpriseDB Tools)