{"id":13309,"date":"2023-10-02T12:25:07","date_gmt":"2023-10-02T16:25:07","guid":{"rendered":"http:\/\/local.brightwhiz\/?p=13309"},"modified":"2023-10-02T12:25:11","modified_gmt":"2023-10-02T16:25:11","slug":"how-to-install-postgresql-16-on-ubuntu-22-04","status":"publish","type":"post","link":"http:\/\/local.brightwhiz\/how-to-install-postgresql-16-on-ubuntu-22-04\/","title":{"rendered":"How to Install PostgreSQL 16 on Ubuntu 22.04"},"content":{"rendered":"\n
PostgreSQL is a powerful open-source relational database management system known for its robustness and flexibility. With each new release, PostgreSQL<\/a> continues to improve and offer new features. Ubuntu 22.04, the latest LTS (Long Term Support) release of Ubuntu, provides an excellent platform for running PostgreSQL 16. In this blog post, we will guide you through the steps to install PostgreSQL 16 on Ubuntu 22.04.<\/p>\n\n\n\n Before you start the installation process, make sure you have the following:<\/p>\n\n\n\n Now, let’s dive into the installation process!<\/p>\n\n\n\n First, it’s essential to ensure that your system is up to date. Open a terminal and run the following command to update the package list and upgrade existing packages:<\/p>\n\n\n\n This command will fetch the latest package information and install any available updates.<\/p>\n\n\n\n PostgreSQL provides an official APT repository for Ubuntu, which makes it easy to install the latest version. To add the PostgreSQL APT repository to your system, run the following commands:<\/p>\n\n\n\n The above command adds the PostgreSQL APT repository to your system’s package sources.<\/p>\n\n\n\n Next, import the repository’s signing key using the following command:<\/p>\n\n\n\n With the repository added and the key imported, it’s time to install PostgreSQL 16. Run the following command:<\/p>\n\n\n\n The After PostgreSQL 16 is installed, it is not automatically started. You need to enable and start the PostgreSQL service using the following commands:<\/p>\n\n\n\n By default, PostgreSQL creates a user named Now, set a password for the Replace If you plan to access PostgreSQL from remote machines, you may need to modify the PostgreSQL configuration to allow remote connections. By default, PostgreSQL only allows connections from the localhost.<\/p>\n\n\n\n To enable remote access, open the PostgreSQL configuration file in a text editor:<\/p>\n\n\n\n Find the Save the file and exit the text editor.<\/p>\n\n\n\n Next, edit the Add the following line at the end of the file to allow all IPv4 and IPv6 addresses to connect:<\/p>\n\n\n\n Save the file and exit the text editor.<\/p>\n\n\n\n Finally, restart PostgreSQL to apply the changes:<\/p>\n\n\n\n Congratulations! You’ve successfully installed PostgreSQL 16 on your Ubuntu 22.04 machine. PostgreSQL is now up and running, ready for you to create databases, tables, and start building your applications with this powerful relational database management system. If you have any specific use cases or configurations in mind, don’t forget to explore the official PostgreSQL documentation<\/a> for further guidance. Enjoy using PostgreSQL on your Ubuntu 22.04 server!<\/p>\n","protected":false},"excerpt":{"rendered":" PostgreSQL is a powerful open-source relational database management system known for its robustness and flexibility. With each new release, PostgreSQL continues to improve and offer new features. Ubuntu 22.04, the…<\/p>\n","protected":false},"author":1,"featured_media":13317,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,23,9,16],"tags":[180,354,424,433,449,955,531,544,591,598],"yoast_head":"\nPrerequisites<\/h2>\n\n\n\n
\n
Step 1: Update System Packages<\/h2>\n\n\n\n
$ sudo apt update && sudo apt upgrade -y<\/code><\/pre>\n\n\n\n
Step 2: Add PostgreSQL APT Repository<\/h2>\n\n\n\n
$ sudo sh -c 'echo "deb http:\/\/apt.postgresql.org\/pub\/repos\/apt $(lsb_release -cs)-pgdg main" > \/etc\/apt\/sources.list.d\/pgdg.list'<\/code><\/pre>\n\n\n\n
$ wget --quiet -O - https:\/\/www.postgresql.org\/media\/keys\/ACCC4CF8.asc | sudo apt-key add -<\/code><\/pre>\n\n\n\n
Step 3: Install PostgreSQL 16<\/h2>\n\n\n\n
$ sudo apt update\n$ sudo apt install postgresql-16 postgresql-contrib-16<\/code><\/pre>\n\n\n\n
postgresql-contrib-16<\/code> package includes additional utilities and extensions for PostgreSQL.<\/p>\n\n\n\n
Step 4: Start and Enable PostgreSQL<\/h2>\n\n\n\n
$ sudo systemctl enable postgresql\n$ sudo systemctl start postgresql<\/code><\/pre>\n\n\n\n
Step 5: Set a Password for the PostgreSQL User (Optional)<\/h2>\n\n\n\n
postgres<\/code> with administrative privileges. You should set a password for this user. To do this, switch to the
postgres<\/code> user and access the PostgreSQL prompt:<\/p>\n\n\n\n
$ sudo -i -u postgres\n$ psql<\/code><\/pre>\n\n\n\n
postgres<\/code> user by running the following SQL command:<\/p>\n\n\n\n
ALTER USER postgres PASSWORD 'your_password';<\/code><\/pre>\n\n\n\n
'your_password'<\/code> with your desired password. After setting the password, exit the PostgreSQL prompt by typing
\\q<\/code> and pressing Enter.<\/p>\n\n\n\n
Step 6: Configure PostgreSQL for Remote Access (Optional)<\/h2>\n\n\n\n
$ sudo nano \/etc\/postgresql\/16\/main\/postgresql.conf<\/code><\/pre>\n\n\n\n
listen_addresses<\/code> line and change it to:<\/p>\n\n\n\n
listen_addresses = '*'<\/code><\/pre>\n\n\n\n
pg_hba.conf<\/code> file:<\/p>\n\n\n\n
$ sudo nano \/etc\/postgresql\/16\/main\/pg_hba.conf<\/code><\/pre>\n\n\n\n
host all all 0.0.0.0\/0 md5\nhost all all ::\/0 md5\n<\/code><\/pre>\n\n\n\n
$ sudo systemctl restart postgresql<\/code><\/pre>\n\n\n\n
Conclusion<\/h2>\n\n\n\n