Setup Postgres DB on Local
Install PostgreSQL 14 / Adminer using Docker Compose
To run it, you need to install PostgreSQL v14 on your local machine or run it through Docker Compose by running the following command:
npm run docker-compose
Everything you need is already configured under docker-compose.yml
file and by running the command above you can easily start a PostgreSQL 14 and Adminer on your local machine.
Installing PostgreSQL 14 on local machine
This guide provides step-by-step instructions for installing PostgreSQL 14 on Windows, macOS, and Linux.
Prerequisites
Before starting the installation, ensure that:
- You have administrative privileges on your system.
- Your system meets the hardware requirements for PostgreSQL.
- You have access to an internet connection.
Installing PostgreSQL 14 on Windows
- Download the Installer
- Visit the official PostgreSQL website.
- Click on Windows and download the installer for PostgreSQL 14.
- Run the Installer
- Double-click the downloaded
.exe
file to start the installation. - Follow the on-screen prompts:
- Select components to install (default options are recommended).
- Choose the installation directory.
- Set a password for the
postgres
superuser. - Select the default port (5432).
- Choose a locale for your database cluster.
- Double-click the downloaded
- Complete the Installation
- After installation, the PostgreSQL service will start automatically.
- Open pgAdmin (a graphical tool for managing PostgreSQL) to verify the installation.
- Verify the Installation
- Open the Command Prompt.
- Run the command:
psql -U postgres
. - Enter the password you set during installation to connect to the database.
Installing PostgreSQL 14 on macOS
Using Homebrew (Recommended)
-
Install Homebrew (if not already installed)
-
Open the Terminal and run:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
-
-
Install PostgreSQL
-
Run the following command:
brew install postgresql@14
-
-
Start PostgreSQL
-
Start the PostgreSQL service:
brew services start postgresql@14
-
-
Verify the Installation
-
Run the
psql
command:psql postgres
-
Using the Installer
-
Download the Installer
- Visit the official PostgreSQL website.
- Click on macOS and download the installer for PostgreSQL 14.
-
Run the Installer
- Open the
.dmg
file and follow the installation wizard. - Set a password for the
postgres
user and configure other options.
- Open the
-
Verify the Installation
-
Open the Terminal and run:
psql -U postgres
-
Installing PostgreSQL 14 on Linux
Using Package Managers (Recommended)
Debian/Ubuntu
-
Update Package Index
-
Open the Terminal and run:
sudo apt update
-
-
Install PostgreSQL
-
Run the following commands:
sudo apt install -y wget gnupg
wget -qO - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
sudo apt update
sudo apt install -y postgresql-14
-
-
Start and Enable PostgreSQL
-
Run:
sudo systemctl start postgresql
sudo systemctl enable postgresql
-
-
Verify the Installation
-
Switch to the
postgres
user and accesspsql
:sudo -i -u postgres
psql
-
CentOS/Red Hat
-
Install PostgreSQL Repository
-
Run the following commands:
sudo dnf install -y https://download.postgresql.org/pub/repos/yum/14/redhat/rhel-$(rpm -E %rhel)-x86_64/pgdg-redhat-repo-latest.noarch.rpm
sudo dnf -qy module disable postgresql
sudo dnf install -y postgresql14 postgresql14-server
-
-
Initialize and Start PostgreSQL
-
Initialize the database:
sudo /usr/pgsql-14/bin/postgresql-14-setup initdb
-
Start and enable the service:
sudo systemctl start postgresql-14
sudo systemctl enable postgresql-14
-
-
Verify the Installation
-
Access
psql
:sudo -i -u postgres
psql
-
Building from Source
-
Install Dependencies
-
For Debian-based systems:
sudo apt update
sudo apt install -y gcc make libreadline-dev zlib1g-dev flex bison -
For Red Hat-based systems:
sudo dnf groupinstall "Development Tools"
sudo dnf install -y readline-devel zlib-devel
-
-
Download and Extract Source Code
-
Visit the PostgreSQL source page and download version 14.
-
Extract the tarball:
tar -xvf postgresql-14.x.tar.gz
cd postgresql-14.x
-
-
Compile and Install
-
Run:
./configure
make
sudo make install
-
-
Initialize the Database
-
Run:
mkdir -p /usr/local/pgsql/data
sudo chown $(whoami) /usr/local/pgsql/data
initdb -D /usr/local/pgsql/data
-
-
Start PostgreSQL
-
Run:
pg_ctl -D /usr/local/pgsql/data -l logfile start
-
-
Verify the Installation
-
Access
psql
:psql -U postgres
-
Post-Installation Steps
- Secure your PostgreSQL installation by configuring user roles and permissions.
- Enable remote access if needed by editing
postgresql.conf
andpg_hba.conf
. - Regularly back up your databases.
For more details, visit the official PostgreSQL documentation.