Install PostgreSQL on WSL
insights Stats
warning Please login first to view stats information.
Raymond
SQL Databases
SQL relational databases incl. SQLite, SQL Server, MySQL, PostgreSQL, Oracle, etc.
Prerequisites
Before installing PostgreSQL on WSL, please ensure you have WSL enabled on your Windows 10 system.
Follow Install Windows Subsystem for Linux on a Non-System Drive to install WSL on a non-C drive.
This tutorial provides steps to install PostgreSQL on WSL Debian distro. You can follow similar steps to install it in other Linux distros.
Step by step guide
- Open Debian distro through WSL command:
wsl -d Debian
- Update Debian packages:
sudo apt update
You need to type user password.
- Install PostgreSQL and -contrib package using the following command:
sudo apt install postgresql postgresql-contrib
Type Y to continue when asked.
- Wait until the installation is completed.
- Verify PostgreSQL version:
$ psql --version psql (PostgreSQL) 9.6.20
- The default admin user is postgres. We need to setup a password for it. Use the following command to setup the password:
sudo passwd postgres
Enter the password. I'm setting the password as 'password'.
$ sudo passwd postgres
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Test PostgreSQL
- Start PostgreSQL service using the following commands:
$ sudo service postgresql start # Or sudo /etc/init.d/postgresql start
- Check the status of the service:
$ sudo service postgresql status # Or sudo /etc/init.d/postgresql status
The output looks like the following:9.6/main (port 5432): online
- Try PostgresSQL prompt using the following command:
sudo -u postgres psql
The above command sudo the default user postgres and then run psql command:
$ sudo -u postgres psql psql (9.6.20) Type "help" for help. postgres=#
- Check databases by typing \l in psql command window:
\l
The output looks like the following screenshot:
- Type \q to exit the CLI.
- Stop the service using the following command:
$ sudo service postgresql stop # Or sudo /etc/init.d/postgresql stop
copyright
This page is subject to Site terms.
comment Comments
No comments yet.