Postgresql install arch linux

How to Install, Configure, and Upgrade PostgreSQL on Arch Linux

PostgreSQL is an open-source Object-Relational Database Management System. This guide explains how to install and upgrade PostgreSQL server on Arch Linux.

Prerequisites

Install PostgreSQL

Install the PostgreSQL package. The installation creates a system user called postgres .

Switch to the postgres user and initialize the database cluster.

$ sudo -u postgres –i initdb -D '/var/lib/postgres/data' 

Exit the postgres user account.

PostgreSQL database server runs as a service under the name postgresql .

Enable the PostgreSQL service to start automatically at every boot.

$ sudo systemctl enable postgresql 

Start the PostgreSQL service.

$ sudo systemctl start postgresql 

Configure PostgreSQL Server

When you first install PostgreSQL, a password for the super-user is not set by default. Use the default PostgreSQL command-line psql to log into the database server.

Create a password for the super-user.

postgres=# \password postgres 

Enter a strong password and confirm.

 Enter new password: EXAMPLE_PASSWORD Enter it again: EXAMPLE_PASSWORD 

Exit the command-line client.

Example PostgreSQL Commands

Here are a few basic PostgreSQL commands.

    Create a database and log in:

$ createdb TestDB $ psql TestDB 

How to Upgrade PostgreSQL

Upgrading PostgreSQL requires extra attention. Make sure you follow the official PostgreSQL Upgrade documentation. Upgrading, if not done properly, can cause data loss. It’s highly recommended that you backup your databases first.

Minor version upgrades are easy and safe to do. However, if you upgrade to a different major version, you might not be able to access your data. Always check the PostgreSQL Official documentation for more details and to be certain of the steps required to upgrade.

Читайте также:  Nvidia linux run file

It’s highly recommended to configure pacman to skip automatic upgrades for PostgreSQL. When an upgrade is released, and you upgrade your entire Arch system, pacman will indicate a new version is available.

Edit /etc/pacman.conf , and add the following:

Minor Version Upgrades

To perform a minor upgrade:

# systemctl stop postgresql 
 # systemctl status postgresql 
 # pacman -S postgresql postgresql-libs postgresql-old-upgrade 
 # systemctl start postgresql 

Major Version Upgrades

It’s recommended to check PostgreSQL’s official website for procedures you must perform for a major version upgrade.

More Information

Use the following commands to manage the PostgreSQL server:

$ sudo systemctl stop postgresql 
$ sudo systemctl start postgresql 
$ sudo systemctl restart postgresql 
$ sudo systemctl reload postgresql 
$ sudo systemctl status postgresql 

Conclusion

In this guide, you’ve learned how to install, configure and update PostgreSQL on Arch Linux. You’ve also used the basic SQL syntax to create a PostgreSQL database.

Want to contribute?

You could earn up to $600 by adding new articles.

Источник

Install PostgreSQL 10 on Arch Linux

Install and Get Started with PostgreSQL 10 on Arch Linux

PostgreSQL is a powerful object-relational database management system. PostgreSQL strongly complies to ANSI SQL standard 2008. It is an open source and cross platform database. It is an enterprise class database. The latest version of PostgreSQL as of this writing is 10.

In this article, I will show you how to install and use PostgreSQL 10 on Arch Linux. Let’s get started.

Installing PostgreSQL 10

First update the package database of pacman package manager with the following command:

The package database of pacman package manager should be updated.

PostgreSQL 10 is available in the official package repository of Arch Linux. So you can install PostgreSQL 10 very easily.

You can run the following command to install PostgreSQL 10 on Arch Linux:

Now press ‘y’ and then press to continue.

Читайте также:  Исполнить бинарный файл linux

PostgreSQL 10 should be installed.

Now you can run the following command to check the version of PostgreSQL you’ve installed.

As you can see from the screenshot below, the version of PostgreSQL installed is 10.2.

Now you can run the following command to check whether PostgreSQL is running or not.

As you can see from the screenshot below, PostgreSQL is not running.

You may think all you have to do now is to start PostgreSQL. But you’re wrong. You can’t start PostgreSQL now as the data directory of PostgreSQL is not initialized yet.

Before you can initialize the data directory of PostgreSQL, you must login as the postgres user with the following command:

You’re logged in as postgres user as you can see from the marked section of the screenshot below.

NOTE: You should always login as postgres user to use or do any type of administration of PostgreSQL. Otherwise you may get permission errors and things might not work as expected.

Now you can initialize the data directory of PostgreSQL with the following command:

NOTE: The default data directory of PostgreSQL on Arch Linux is /var/lib/postgres/data

As you can see from the screenshot below, the data directory is being initialized.

The data directory is generated at this stage.

Now logout of postgres user with the following command:

You should be logged out of postgres user account.

Now that the data directory of PostgreSQL is generated, you can start PostgreSQL with the following command:

You can run the following command to check whether PostgreSQL is running again with the following command:

As you can see from the screenshot below, the PostgreSQL database server is running.

Now you should add PostgreSQL to the system startup so that it will start automatically on system boot.

Run the following command to add PostgreSQL to system startup:

PostgreSQL should be added to the system startup as you can see from the screenshot below.

Читайте также:  Linux print ip address

Using PostgreSQL 10

In this section I will show you the basics of PostgreSQL 10.

Before you do anything, log in as postgres user with the following command:

You’re logged in as postgres user.

Creating a Database:

You can use the createdb command to create a database in PostgreSQL.

Let’s say you want to create a database linuxhint. You can run the following command to create linuxhint database:

The linuxhint database should be created.

Using a Database

You can use psql command to login to an existing database that you created with createdb command.

You can run the following command to login to linuxhint database.

As you can see from the screenshot below, you’re logged in to the linuxhint database.

Executing SQL Command

Once you’re logged in to a database using psql command, you can execute PostgreSQL compatible SQL commands.

For example, you can run the following SQL statement to check the current date.

As you can see from the screenshot below, the current date is printed.

Creating a Table on PostgreSQL:

You can run the following SQL statements to create a table users on PostgreSQL:

As you can see a table users is created.

Inserting into the Table

You can insert into the newly created users table using the following SQL statement:

As you can see 1 row is inserted into the users table.

Selecting Data from Table

You can run the following SQL statement to select all the data from the users table.

As you can see the data I inserted was retrieved.

That’s how you install and get started with PostgreSQL 10 on Arch Linux. Thanks for reading this article.

About the author

Shahriar Shovon

Freelancer & Linux System Administrator. Also loves Web API development with Node.js and JavaScript. I was born in Bangladesh. I am currently studying Electronics and Communication Engineering at Khulna University of Engineering & Technology (KUET), one of the demanding public engineering universities of Bangladesh.

Источник

Оцените статью
Adblock
detector