{"id":27610,"date":"2018-08-07T07:00:01","date_gmt":"2018-08-07T12:00:01","guid":{"rendered":"https:\/\/www.rosehosting.com\/blog\/?p=27610"},"modified":"2022-06-03T03:34:45","modified_gmt":"2022-06-03T08:34:45","slug":"how-to-install-postgresql-on-debian-9","status":"publish","type":"post","link":"https:\/\/www.rosehosting.com\/blog\/how-to-install-postgresql-on-debian-9\/","title":{"rendered":"How To Install PostgreSQL on Debian 9"},"content":{"rendered":"
<\/p>\n
We will show you how to install PostgreSQL on Debian 9. PostgreSQL is an object-relational database management system written in C. It is free and open-source database system which main features are to store the data securely and to return the data as response to other applications requests. Installing\u00a0PostgreSQL on Debian 9 is fairly easy task, and it shouldn’t take more then 10 minutes to finish installing\u00a0PostgreSQL on Debian 9. Let’s get started.<\/p>\n
<\/p>\n
Before you start with the installation steps, make sure that you have a full root access to your Debian 9 VPS<\/a>, or at least you have a system user with sudo privileges<\/a>. If you do, connect to your server via SSH<\/a> and make sure all your system software is up to date. First, update the package index using the following command:<\/p>\n Once the package index is updated, you can go ahead an update all your system software to the latest version using the command below:<\/p>\n This may take from few seconds to few minutes depending on the software that needs to be updated.<\/p>\n The next step is to install the PostgreSQL database system on your Debian 9 VPS<\/a>. This step is fairly simple, just run the following command:<\/p>\n It will install the PostgreSQL database server, client and other required tools.<\/p>\n To check an verify that PosgreSQL server\/client are installed, you can use the following command:<\/p>\n It will show you the current version of PostgreSQL you have installed on your server:<\/p>\n Now that the installation of PostgreSQL is completed, it is good to know how you can manage the PostgreSQL service on your PostgreSQL VPS<\/a>. To start the PostgreSQL service, run the following command on the terminal:<\/p>\n To stop the PostgreSQL service, you can use the following command:<\/p>\n To restart the service, you can run the following command:<\/p>\n To check the status of the PostgreSQL service, run the following command:<\/p>\n If PostgreSQL is up and running on your Linux VPS<\/a> at the moment, the output will be similar to the one below:<\/p>\n To enable the PostgreSQL service on system boot, run the following command:<\/p>\n In case you want PostgreSQL disabled on system boot, run the following command:<\/p>\n If you want to manage the PostgreSQL file locations, connections and authentication, resource usage, logging etc. you need to edit the main configuration file. The main configuration file for PostgreSQL is located in You can use any text editor of your choice to open and edit the configuration file for PostgreSQL. The file consists of lines of form of To access the PostgreSQL command line interface and manage the databases, you should log in as Now, to enter to the PostgreSQL interactive terminal run the following command:<\/p>\n Your shell will change as follows:<\/p>\n Now you can execute command specific to PostgreSQL. For example, to list all current databases you can type You can also create databases and tables, insert data, retrieve data and do many other things using the PostgreSQL interactive terminal. For more information you can check the official PostgreSQL documentation.<\/p>\n If you prefer using a graphical user interface to manipulate the databases and the data stored, we can recommend you to install and use phpPgAdmin<\/a>. It is a web-based administration tool for PostgreSQL similar to phpMyAdmin for managing the MySQL database system.<\/p>\n Of course, you don\u2019t have to install PostgreSQL on Debian 9, if you use one of our PostgreSQL VPS Hosting<\/a> plans, in which case you can simply ask our expert Linux admins to install PostgreSQL on Debian 9 for you. They are available 24\u00d77 and will take care of your request immediately.<\/p>\n PS<\/strong><\/span>. If you liked this post on how to install PostgreSQL on Debian 9, please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.<\/p>\n","protected":false},"excerpt":{"rendered":" We will show you how to install PostgreSQL on Debian 9. PostgreSQL is an object-relational database management system written in … <\/p>\napt-get update<\/pre>\n
apt-get upgrade<\/pre>\n
Install PostgreSQL on Debian 9<\/h3>\n
apt-get install postgresql<\/pre>\n
psql --version<\/pre>\n
# psql --version\r\npsql (PostgreSQL) 9.6.7<\/pre>\n
Manage PostgreSQL on Debian 9<\/h3>\n
systemctl start postgresql.service<\/pre>\n
systemctl stop postgresql.service<\/pre>\n
systemctl restart postgresql.service<\/pre>\n
systemctl status postgresql.service<\/pre>\n
# systemctl status postgresql.service\r\npostgresql.service - PostgreSQL RDBMS\r\n Loaded: loaded (\/lib\/systemd\/system\/postgresql.service; enabled; vendor preset: enabled)\r\n Active: active (exited) since Sat 2018-07-21 10:57:16 CDT; 40min ago\r\n Main PID: 1018 (code=exited, status=0\/SUCCESS)\r\n CGroup: \/system.slice\/postgresql.service\r\n<\/pre>\n
systemctl enable postgresql.service<\/pre>\n
systemctl disable postgresql.service<\/pre>\n
\/etc\/postgresql\/VERSION-NUMBER\/main<\/code> directory. So if your PostgreSQL version is 9.6, the location will be
\/etc\/postgresql\/9.6\/main\/postgresql.conf<\/code><\/p>\n
NAME = VALUE<\/code> and make sure the changes you make are valid. Otherwise, PostgreSQL will not work. The configuration file is read on server startup so when you make changes you need to restart the PostgreSQL service in order for the changes to take effect.<\/p>\n
systemctl restart postgresql.service<\/pre>\n
Basic PostgreSQL usage on Debian 9<\/h3>\n
postgres<\/code> system user. Run the following command:<\/p>\n
su - postgres<\/pre>\n
psql<\/pre>\n
~$ psql\r\npsql (9.6.7)\r\nType \"help\" for help.\r\n\r\npostgres=#<\/pre>\n
\\l<\/code> and press
Enter<\/code><\/p>\n
postgres=# \\l\r\n List of databases\r\n Name | Owner | Encoding | Collate | Ctype | Access privileges\r\n-----------+----------+----------+-------------+-------------+-----------------------\r\n postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |\r\n template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c\/postgres +\r\n | | | | | postgres=CTc\/postgres\r\n template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c\/postgres +\r\n | | | | | postgres=CTc\/postgres\r\n(3 rows)\r\n<\/pre>\n
\n