Installer la base de données PostgreSQL sur Ubuntu
View more Tutorials:


- Ubuntu 14, 16, 18, 20
- PostGres 9.6, 10, 11, 12

cat /etc/*release

Version |
Code name |
Release date |
End of Life date |
Ubuntu 20.4 LST | focal | August 13, 2020 | |
Ubuntu 18.04.1 LTS |
bionic |
July 26, 2018 |
April 2023 |
Ubuntu 18.04 LTS |
bionic |
April 26, 2018 |
April 2023 |
Ubuntu 16.04.4 LTS |
xenial |
March 1, 2018 |
April 2021 |
Ubuntu 16.04.3 LTS |
xenial |
August 3, 2017 |
April 2021 |
Ubuntu 16.04.2 LTS |
xenial |
February 16, 2017 |
April 2021 |
Ubuntu 16.04.1 LTS |
xenial |
July 21, 2016 |
April 2021 |
Ubuntu 16.04 LTS |
xenial |
April 21, 2016 |
April 2021 |
Ubuntu 14.04.5 LTS |
trusty |
August 4, 2016 |
April 2019 |
Ubuntu 14.04.4 LTS |
trusty |
February 18, 2016 |
HWE August 2016 |
Ubuntu 14.04.3 LTS |
trusty |
August 6, 2015 |
HWE August 2016 |
Ubuntu 14.04.2 LTS |
trusty |
February 20, 2015 |
HWE August 2016 |
Ubuntu 14.04.1 LTS |
trusty |
July 24, 2014 |
April 2019 |
Ubuntu 14.04 LTS |
trusty |
April 17, 2014 |
April 2019 |
sudo add-apt-repository "deb https://apt.postgresql.org/pub/repos/apt/ {UBUNTU_CODENAME}-pgdg main"
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get install postgresql-12
sudo add-apt-repository "deb https://apt.postgresql.org/pub/repos/apt/ focal-pgdg main"
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get install postgresql-12
sudo add-apt-repository "deb https://apt.postgresql.org/pub/repos/apt/ bionic-pgdg main"
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get install postgresql-12
sudo add-apt-repository "deb https://apt.postgresql.org/pub/repos/apt/ xenial-pgdg main"
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get install postgresql-9.6
If you receive an error when installing, please see the appendix at the end of this post:E: The method driver /usr/lib/apt/methods/https could not be found. N: Is the package apt-transport-https installed? E: Failed to fetch https://apt.postgresql.org/pub/repos/apt/dists/xenial-pgdg/InRelease E: Some index files failed to download. They have been ignored, or old ones used instead.
sudo service postgresql start
sudo -u postgres psql


ALTER USER postgres PASSWORD 'newpassword';


psql -U postgres -h localhost




CREATE USER myuser with PASSWORD '123';
CREATE DATABASE mydb;
GRANT ALL PRIVILEGES ON DATABASE mydb TO myuser;






psql -U myuser -h localhost -d mydb


-- Create table Account
Create table Account (User_Name varchar(30), Full_Name varchar(64) ) ;
-- Insert 2 row to Account.
Insert into Account(user_name, full_name) values ('gates', 'Bill Gate');
Insert into Account(user_name, full_name) values ('edison', 'Thomas Edison');
-- Query
Select * from Account;







E: The method driver /usr/lib/apt/methods/https could not be found.
N: Is the package apt-transport-https installed?
E: Failed to fetch https://apt.postgresql.org/pub/repos/apt/dists/xenial-pgdg/InRelease
E: Some index files failed to download. They have been ignored, or old ones used instead.

sudo apt-get install apt-transport-https

