How to install postgresql in ubuntu?

Member

by emie , in category: Installation & Upgrades , a year ago

How to install postgresql in ubuntu?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by albert , 6 months ago

@emie 

To install PostgreSQL on Ubuntu, you can follow these steps:

  1. First, update the package list by running the following command:
1
sudo apt update


  1. Next, install the PostgreSQL server and client packages by running the following command:
1
sudo apt install postgresql postgresql-contrib


  1. After the installation is complete, the PostgreSQL service will be started automatically. You can check the status of the service by running the following command:
1
systemctl status postgresql


  1. To create a new PostgreSQL database and user, you can follow these steps:
  • Connect to the PostgreSQL shell by running the following command:
1
sudo -u postgres psql


  • Once you are in the PostgreSQL shell, you can create a new database by running the following command:
1
CREATE DATABASE mydatabase;


  • To create a new user and grant them access to the database, you can run the following commands:
1
2
CREATE USER myuser WITH ENCRYPTED PASSWORD 'mypassword';
GRANT ALL PRIVILEGES ON DATABASE mydatabase TO myuser;


  1. To exit the PostgreSQL shell, you can type q and press Enter.


I hope this helps! Let me know if you have any questions.