postgres – TecAdmin https://tecadmin.net How to guide for System Administrator's and Developers Wed, 16 Nov 2022 05:48:44 +0000 en-US hourly 1 https://wordpress.org/?v=6.1.1 How To Configure PostgreSQL to Allow Remote Connections https://tecadmin.net/postgresql-allow-remote-connections/ https://tecadmin.net/postgresql-allow-remote-connections/#comments Thu, 23 Sep 2021 11:12:33 +0000 https://tecadmin.net/?p=27027 An open-source, object-based relational database PostgreSQL, provides the user with the implementation of SQL and is commonly hosted on Linux. With PostgreSQL users can expand the system by defining self-data types, functions, and operators. PostgreSQL is used by many large companies to save and store their data for various applications and it supports various programming [...]

The post How To Configure PostgreSQL to Allow Remote Connections appeared first on TecAdmin.

]]>
An open-source, object-based relational database PostgreSQL, provides the user with the implementation of SQL and is commonly hosted on Linux. With PostgreSQL users can expand the system by defining self-data types, functions, and operators.

PostgreSQL is used by many large companies to save and store their data for various applications and it supports various programming interfaces as well as videos, texts, and images. In this article we’ll first go through the installation of PostgreSQL on ubuntu 20.04 then we’ll configure it to allow remote connection

Prerequsities

This article assumes that you already have running a PostgreSQL server on your system. If not, use one of the below links to install the PostgreSQL database server on your system.

  1. Installing PostgreSQL on Ubuntu 20.04
  2. Installing PostgreSQL on CentOS 8

Find Configuration File

In order to install PostgreSQL on our system we need to update our repository and for that execute the below command:

sudo -u postgres psql -c "SHOW config_file;" 
Output:
config_file ----------------------------------------- /etc/postgresql/13/main/postgresql.conf (1 row)

You need to change the listening address in the postgresql.conf configuration file showing in the command output. Also, you need to edit “pg_hba.conf” in the same directory to allow remote access.

Configure PostgreSQL to Allow Remote Connections

In order to allow all the IP addresses to connect to the PostgreSQL server, we need to configure the file and make some changes, for that you have located the configuration file in the previous step.

  1. Configuring postgresql.conf:
  2. Now we need to open the file and make some changes in order to allow a remote connection. To open the file you’ve to use the keyword “nano” or you can run the command in the terminal that is provided below:

    sudo nano /etc/postgresql/13/main/postgresql.conf 
    

    This command will open this file and in it, you need to search “listen_addresses” and add the following line.

    #listen_addresses = 'localhost'
    listen_addresses = '*'
    
    Change Postgres Listen Address
    Change Listen Address in PostgreSQL

    All you’ve to do is change the listening address from localhost to “*” or add a new line as shown above. This will allow every IP address to be connected to the database server, or if you want to specify some particular ips you can type them with spaces between each IP address.

  3. Configuring pg_hba.conf:
  4. In order to allow the users that we want to be connected to the database then we need to make changes in the “pg_hba.conf” file. This file will be available under the same directory as above.

    Now open the file using the command provided below:

    sudo nano /etc/postgresql/13/main/pg_hba.conf 
    

    In the file you’ve to add the following lines in file:

    # TYPE  DATABASE	USER	ADDRESS   	METHOD
    host    all     	all     0.0.0.0/0       md5
    host    all             all     :/0             md5
    
    PostgreSQL Allow Remote Hosts
    Allow Remote Hosts in PostgreSQL

    Save the configuration file and close it.

  5. Restart Service :
  6. Now, restart the database service to apply changes by executing the below-mentioned command:

    sudo systemctl restart postgresql 
    

    Now simply open the port “5432” in the firewall and you’re all set to see all the databases and you can bond from whichever ip address to the server of PostgreSQL:

    sudo ufw allow 5432 
    

That’s it. Your PostgreSQL database server is accessible from remote hosts.

Conclusion

PostgreSQL database is default set to bond with localhost which restricts the other IP address and host to connect or have the access to the PostgreSQL server. In this article, we guided you through the configuration of PostgreSQL to allow remote connection so that other IPs can bond to the server. In this way, other hosts can easily see the list of databases and connect to the PostgreSQL server remotely.

The post How To Configure PostgreSQL to Allow Remote Connections appeared first on TecAdmin.

]]>
https://tecadmin.net/postgresql-allow-remote-connections/feed/ 2
How to Check the PostgreSQL Version https://tecadmin.net/check-postgres-version/ https://tecadmin.net/check-postgres-version/#respond Thu, 05 Aug 2021 12:42:49 +0000 https://tecadmin.net/?p=27021 PostgreSQL is an advanced, open-source relational database management system. It is written in C programming language and was developed at the University of California, Berkeley in 1996. Initially, version 1.0 of Postgres95 was announced on September 5, 1995. The first non-university version of PostgreSQL was provided on July 8, 1996, by Marc Fournier at Hub.org [...]

The post How to Check the PostgreSQL Version appeared first on TecAdmin.

]]>
PostgreSQL is an advanced, open-source relational database management system. It is written in C programming language and was developed at the University of California, Berkeley in 1996. Initially, version 1.0 of Postgres95 was announced on September 5, 1995. The first non-university version of PostgreSQL was provided on July 8, 1996, by Marc Fournier at Hub.org Networking Services. Which is the first version of PostgreSQL for public use.

As of today, PostgreSQL 13.3 is the latest stable version available for installation. PostgreSQL version 9.5 and lower versions are no more supported by the team.

In this tutorial, you will learn, how to check the PostgreSQL version on your system.

How to Find PostgreSQL Version using Command line

Use one of the following methods to check the PostgreSQL version via the command line.

  1. Check Version with Login

    Once you login to the PostgreSQL server via terminal, The post login screen displays the PostgreSQL version you have connected to.

    psql 
    
    Output:
    psql (13.3 (Ubuntu 13.3-1.pgdg20.04+1)) Type "help" for help.
  2. The above output displays, that you are running version 13.3 of PostgreSQL server.

  3. Check Version with version() Function

    You can also execute version() function to find out the PostgreSQL version. This method can also help you to check PostgreSQL version in automation scripts.

    SELECT version();
    
    Output:
    version ------------------------------------------------------------------------------------ PostgreSQL 13.3 (Ubuntu 13.3-1.pgdg20.04+1) on x86_64-pc-linux-gnu, compiled by gcc (1 row)
  4. Check Version with Parameters

    Alternatively, you can also find the PostgreSQL version by the preset parameters, and you can also use this method for automatic version checks.

    SHOW server_version;
    
    Output:
    server_version ---------------------------------- 13.3 (Ubuntu 13.3-1.pgdg20.04+1) (1 row)

Check the below screenshot for all commands in action to check the Postgres version on command line.

Find PostgreSQL Version

How to Find Postgres Version in pgAdmin4

pgAdmin4 is an excellent web interface for managing the PostgreSQL servers. So the pgAdmin4 users can also find the Postgres version on the web interface.

To get the version, follow:

  1. Login to pgAdmin4
  2. In the left sidebar, expand the Servers and select your Postgres server
  3. Go to Properties tab
  4. Under the General section, check for PostgreSQL version.

Check Postgres Version in PgAdmin4

Conclusion

In this tutorial, you have learned 3 methods to check the PostgreSQL version via the command line. Also provided the steps to find version in pgAdmin4.

The post How to Check the PostgreSQL Version appeared first on TecAdmin.

]]>
https://tecadmin.net/check-postgres-version/feed/ 0
How to Install PostgreSQL and pgAdmin4 in Ubuntu 20.04 https://tecadmin.net/how-to-install-postgresql-in-ubuntu-20-04/ https://tecadmin.net/how-to-install-postgresql-in-ubuntu-20-04/#comments Wed, 07 Apr 2021 06:25:42 +0000 https://tecadmin.net/?p=25098 PostgreSQL is a powerful, reliable, robust and open source object-relational database system. The latest version of this database system is PostgreSQL 13.2, while versions 12.6, 11.11, 10.16, 9.6.21, & 9.5.25 still getting regular updates. This tutorial describes how to install the latest PostgreSQL on Ubuntu 20.04 LTS Linux system. Also, include the steps to install [...]

The post How to Install PostgreSQL and pgAdmin4 in Ubuntu 20.04 appeared first on TecAdmin.

]]>
PostgreSQL is a powerful, reliable, robust and open source object-relational database system.

The latest version of this database system is PostgreSQL 13.2, while versions 12.6, 11.11, 10.16, 9.6.21, & 9.5.25 still getting regular updates.

This tutorial describes how to install the latest PostgreSQL on Ubuntu 20.04 LTS Linux system. Also, include the steps to install pgAdmin4.

Prerequisites

A running Ubuntu 20.04 LTS system with shell access.

Log in as a sudo user and press “CTRL+ALT+T” to open a terminal. Then install a few required packages.

sudo apt update 
sudo apt install wget curl ca-certificates 

Step 1 – Install PostgreSQL in Ubuntu 20.04

First of all, Import the repository signing GPG key to your system. Open a terminal and use the below command to import key:

wget -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add - 

Next, create a PPA file for PostgreSQL on your Ubuntu 20.04 system.

sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ focal-pgdg main" >> /etc/apt/sources.list.d/pgdg.list' 

After adding the PPA to your system. Execute the following command to install the PostgreSQL server on your system.

sudo apt update 
sudo apt-get install postgresql postgresql-contrib 

Installing PostgreSQL in Ubuntu 20.04

Press ‘y’ for any confirmation prompted by the installer. The above command will install the latest version of the PostgreSQL server on your Ubuntu system.

After successful installation verify the PostgreSQL service:

sudo systemctl status postgresql 

Installing postgresql Ubuntu 20.04 LTS

Step 2 – Connection To PostgreSQL

Now, establish a connection with the newly installed Postgres database server. First switch to the system’s Postgres user account:

sudo su - postgres 

then type “psql” to get the postgress prompt:

psql 

psql (13.2 (Ubuntu 13.2-1.pgdg20.04+1))
Type "help" for help.

postgres=#

Connect PostgreSQL in Ubuntu 20.04

Instead of switching users to connect to PostgreSQL, You can also combine both of the above commands as a single command.

sudo -u postgres psql

psql (13.2 (Ubuntu 13.2-1.pgdg20.04+1))
Type "help" for help.

postgres=#

Once you are connected to PostgreSQL and you can see the connection information’s details, use the following command:

postgres=# \conninfo

The output displays information on the database name, the account you are logged in to, the socket path, and the port number.

PostgreSQL connection information in Ubuntu 20.04

Step 3 – Secure PostgreSQL

PostgreSQL installer creates a user “postgres” on your system. Default this user is not protected.

First, create a password for the “postgres” user account by running the following command.

sudo passwd postgres 

Next, switch to the “postgres” account Then switch to the Postgres system account and create a secure and strong password for PostgreSQL administrative database user/role as follows.

su - postgres 
psql -c "ALTER USER postgres WITH PASSWORD 'secure_password_here';" 
exit 

Restart the service to apply security changes.

sudo systemctl restart postgresql 

Step 4 – Install pgAdmin

We can use the official pgAdmin4 PPA to install the latest version of pgAdmin on your system.

First, import the repository signing GPG key and add the pgAdmin4 PPA to your system using the following commands.

curl https://www.pgadmin.org/static/packages_pgadmin_org.pub | sudo apt-key add -
sudo sh -c 'echo "deb https://ftp.postgresql.org/pub/pgadmin/pgadmin4/apt/focal pgadmin4 main" > /etc/apt/sources.list.d/pgadmin4.list' 

After adding the PPA, update the Apt cache and install the pgAdmin4 package on your system.

sudo apt update
sudo apt install pgadmin4 

The pgadmin4 package contains both pgadmin4-web and pgadmin4-desktop versions, Here:

  • pgadmin4-web – Provides the web interface accessible in a web browser
  • pgadmin4-desktop – Provides desktop application for Ubuntu system, which required Ubuntu Desktop system.

You can install both or one of them of your choice. If you have installed both or pgadmin4-web, run the below command to configure it. This will add a login screen to the pgAdmin4 web dashboard.

sudo /usr/pgadmin4/bin/setup-web.sh 

The above script will prompt you to create a user to access the web interface. Input an email address and password when prompted. Say “y” for other confirmation asked by the script.

Once the script finished, you are good to access the pgAdmin web dashboard. It will be available at the below address:

Access this in a web browser: http://localhost/pgadmin4

Login to pgAdmin3 web

In any case, the above page is not loading, restart the Apache server using “sudo systemctl restart apache2“. Again try to load the above URL

Now login with the email address and password configured with /usr/pgadmin4/bin/setup-web.sh script. After successful login to pgAdmin4, you will see the below screen.

Add server to pgAdmin4

Here you need to add your Postgres server to pgAdmin4. Click on the “Add New Server” button. This will open a popup, Enter a friendly name, database host, and Postgres login credentials.

Click “Save” to complete the connection.

On successful authentication, you will see the databases in the sidebar as shown below screenshot.

pgAdmin4 connected to database server

All done. You have successfully added the Postgres database server to pgAdmin4. You can also add more database instances to a single pgAdmin4 server.

Conclusion

In this tutorial, you have learned to install a PostgreSQL server on a Ubuntu 20.04 system. Additionally, you have learned to install and configure pgAdmin4 on your system.

Next, you can learn about backup and restore Postgres databases via command line.

The post How to Install PostgreSQL and pgAdmin4 in Ubuntu 20.04 appeared first on TecAdmin.

]]>
https://tecadmin.net/how-to-install-postgresql-in-ubuntu-20-04/feed/ 6
How To Install PostgreSQL and pgAdmin4 in Fedora 35/34 https://tecadmin.net/how-to-install-postgresql-and-pgadmin-in-fedora/ https://tecadmin.net/how-to-install-postgresql-and-pgadmin-in-fedora/#comments Tue, 30 Oct 2018 16:10:54 +0000 https://tecadmin.net/?p=17323 PostgreSQL is an open-source object-relational, highly scalable, SQL-compliant database management system. It is developed at the University of California at Berkeley’s Computer Science Department. At the time of the last update of this article, PostgreSQL 13 is the latest stable version available for production servers. PostgreSQL 14 is under the development mode and not suggested [...]

The post How To Install PostgreSQL and pgAdmin4 in Fedora 35/34 appeared first on TecAdmin.

]]>
PostgreSQL is an open-source object-relational, highly scalable, SQL-compliant database management system. It is developed at the University of California at Berkeley’s Computer Science Department. At the time of the last update of this article, PostgreSQL 13 is the latest stable version available for production servers. PostgreSQL 14 is under the development mode and not suggested for production users.

pgAdmin4 is a client application used for managing PostgreSQL servers graphically. It is available as a desktop application for Linux desktop systems as well as a web application. Which provides a beautiful and easy-to-use web interface and helps us to increase productivity.

This article will help you to install the PostgreSQL server on Fedora 34/33 Linux system. Also, provide you the instructions to install pgAdmin4 on the Fedora system. This article has been tested with the Fedora version 34.

Step 1 – Installing PostgreSQL on Fedora

Follow the below instructions to install the PostgreSQL server on a Fedora system.

1. First of all, search for the available DNF modules contains the PostgreSQL server packages. Open a terminal and type the below command:

sudo dnf module list postgresql 

DNF search for PostgrSQL repositories

2. In the above command, you will see the available PostgreSQL versions. Now enable the repository of the required version. The below command will enable the repository for the PostgreSQL 13 on your system.

sudo dnf module enable postgresql:13 

Enable PostgreSQL Repository with DNF

3. Once you have successfully enabled the required DNF module. Use the following command to install the PostgreSQL server packages using DNF package manager. This will also install additional required packages on your system.

sudo dnf install postgresql-server 

Press ‘y’ to confirm and finish the packages installation.

4. After that, you need to initialize the PostgreSQL data directory. In other words, this will create a data directory and other configuration files on your system.

To initialize the database server, type:

sudo postgresql-setup --initdb 

Initialize PostgreSQL environment on Fedora

After finishing the above command, the PostgreSQL server installation is completed on your Fedora system. PostgreSQL server uses PGDATA environment variable to contain the data directory location.

Setp 2 – Manage PostgreSQL Service

To start the PostgreSQL service use the following command as per your operating systems. Also, enable the PostgreSQL service to autostart on system boot.

sudo systemctl enable postgresql 
sudo systemctl start postgresql 

You can see the current status of the service using the following command.

sudo systemctl status postgresql 

Managing PostgreSQL service on Fedora

Step 3 – Secure Postgres User

After completing the above steps. Your PostgreSQL 11 server is ready to use. Log in to the postfix instance to verify the connection.

su - postgres -c "psql" 

You may create a strong password for the “postgres” account to enhance server security.

postgres=# \password postgres

Create password for "postgres" default account

Step 4 – Installing pgAdmin4 on Fedora

The pgAdmin4 is a great tool for managing PostgreSQL server databases with a graphical interface. It is available as an application for desktop systems. Also, a web version is available to access in a web browser. The below steps will help you to set pgAdmin4 on your Fedora system.

1. First, configure the pgAdmin4 repository to your Fedora system. In a terminal execute the following command.

sudo rpm -Uvh https://ftp.postgresql.org/pub/pgadmin/pgadmin4/yum/pgadmin4-fedora-repo-2-1.noarch.rpm 

2. After that, install the pgadmin4-web package on your system. This will also add other dependencies to your system.

sudo dnf install pgadmin4-web 

Installing pgAdmin web interface on Fedora

3. The policycoreutils-python-utils package contains the management tools use to manage an SELinux environment for the Python applications. Install it on your system with the following command.

sudo dnf install policycoreutils-python-utils 

4. Finally, run a shell script to configure the pgAdmin4 on your system. This will prompt for an email address and password to enable web application authentication.

sudo /usr/pgadmin4/bin/setup-web.sh 

Configure pgAdmin Environment on Fedora

Remember that, this authentication is just for login to the pgAdmin4 dashboard. It can’t be used to log in to the PostgreSQL server.

Step 5 – Allow Public Access to pgAdmin4

The Fedora systems use a firewall to protect the server from external users. You need to allow access on port 80 to access pgAdmin4 from outside of the server.

To open web port in firewall, type:

sudo firewall-cmd --add-port=80/tcp --permanent 
sudo firewall-cmd --reload 

As the Fedora system has default SELinux in enforcing mode, you need to apply SELinux setting to allow network access to the webserver.

sudo setsebool -P httpd_can_network_connect 1 

In the end, restart the Apache service to reload all the settings and changes.

sudo systemctl restart httpd 

Step 6 – Access pgAdmin4

Now, you can access the pgAdmin4 web application in a web browser. Access your server with the IP address following with /pgadmin4

http(s)://server-ip/pgadmin4

Login to pgAdmin on Fedora

Enter login credentials created in the above step. After a successful login, you will get access to the pgAdmin4 dashboard. Here you can connect multiple PostgreSQL servers and manage them.

pgAdmin Dashboard on Fedora

Conclusion

In conclusion, You have successfully installed the PostgreSQL server on the Fedora Linux system. Additionally, provides you instructions to install the pgAdmin4 dashboard to manage the PostgreSQL server graphically.

The post How To Install PostgreSQL and pgAdmin4 in Fedora 35/34 appeared first on TecAdmin.

]]>
https://tecadmin.net/how-to-install-postgresql-and-pgadmin-in-fedora/feed/ 6
How to Install PostgreSQL 11 on CentOS/RHEL 7/6 https://tecadmin.net/install-postgresql-11-on-centos/ https://tecadmin.net/install-postgresql-11-on-centos/#comments Mon, 29 Oct 2018 16:24:58 +0000 https://tecadmin.net/?p=17315 PostgreSQL 11 Released. It is an open-source object-relational, highly scalable, SQL-compliant database management system. PostgreSQL is developed at the University of California at Berkeley Computer Science Department. This article will help you to install PostgreSQL 11 on CentOS/RHEL 7/6 system. This article has been tested on CentOS Linux release 7.5 Step 1 – Configure Yum [...]

The post How to Install PostgreSQL 11 on CentOS/RHEL 7/6 appeared first on TecAdmin.

]]>
PostgreSQL 11 Released. It is an open-source object-relational, highly scalable, SQL-compliant database management system. PostgreSQL is developed at the University of California at Berkeley Computer Science Department. This article will help you to install PostgreSQL 11 on CentOS/RHEL 7/6 system.

This article has been tested on CentOS Linux release 7.5

Step 1 – Configure Yum Repository

Firstly you need to configure the PostgreSQL repository in your system. Use one of the below commands as per your operating system version.

sudo yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm

For more details visit PostgreSQL repositories link page where you can get repository package rpm for various operating systems.

Step 2 – Installing PostgreSQL on CentOS 7

After enabling PostgreSQL yum repository in your system use following command to install PostgreSQL 11 on your system with yum package manager.

yum install postgresql11-server

This will also install some additional required packages on your system. Enter y to confirm and complete the installation process.

Install PostgreSQL 11 on CentOS

Step 3 – Initialize PGDATA

After that, you need to initialize the PostgreSQL instance. In other words, this will create a data directory and other configuration files on your system. To initialize the database use the below command.

/usr/pgsql-11/bin/postgresql-11-setup initdb

Initialize PostgreSQL 11 on CentOS

The above command will take some time to initialize PostgreSQL first time. PGDATA environment variable contains the path of data directory.

PostgreSQL 11 default data directory location is /var/lib/pgsql/11/data

Setp 4 – Start PostgreSQL Server

To start PostgreSQL service using the following command as per your operating systems. Also, enable PostgreSQL service to autostart on system boot.

systemctl enable postgresql-11.service
systemctl start postgresql-11.service

Step 5 – Verify PostgreSQL Installation

After completing the above all steps. Your PostgreSQL 11 server is ready to use. Log in to your server to verify the connection.

su - postgres -c "psql"

psql (11.0)
Type "help" for help.

postgres=# 

You may create a password for user postgres for security purposes.

postgres=# \password postgres

In conclusion, You have successfully installed the PostgreSQL database server on CentOS/RHEL 7 system.

The post How to Install PostgreSQL 11 on CentOS/RHEL 7/6 appeared first on TecAdmin.

]]>
https://tecadmin.net/install-postgresql-11-on-centos/feed/ 9
How to Install PostgreSQL on CentOS/RHEL 7 https://tecadmin.net/install-postgresql-server-centos/ https://tecadmin.net/install-postgresql-server-centos/#comments Tue, 03 Oct 2017 16:31:33 +0000 https://tecadmin.net/?p=9609 PostgreSQL 10 Released. PostgreSQL is an open-source object-relational, highly scalable, SQL-compliant database management system. PostgreSQL is developed at the University of California at Berkeley Computer Science Department. This article will help you to install PostgreSQL 10 on CentOS, RHEL and Fedora Systems. Step 1 – Add Postgres Yum Repository The first step is to install [...]

The post How to Install PostgreSQL on CentOS/RHEL 7 appeared first on TecAdmin.

]]>
PostgreSQL 10 Released. PostgreSQL is an open-source object-relational, highly scalable, SQL-compliant database management system. PostgreSQL is developed at the University of California at Berkeley Computer Science Department. This article will help you to install PostgreSQL 10 on CentOS, RHEL and Fedora Systems.

Step 1 – Add Postgres Yum Repository

The first step is to install PostgreSQL repository in your system, Use one of below commands as per your system architecture and operating system.

## CentOS/RHEL - 7
rpm -Uvh https://yum.postgresql.org/10/redhat/rhel-7-x86_64/pgdg-centos10-10-2.noarch.rpm

## CentOS/RHEL - 6
rpm -Uvh https://yum.postgresql.org/10/redhat/rhel-6-x86_64/pgdg-redhat10-10-2.noarch.rpm

For more details visit PostgreSQL repositories link page where you can get repository package rpm for various operating systems.

Step 2 – Install PostgreSQL 10 Server

After enabling PostgreSQL yum repository in your system use following command to install PostgreSQL 10 on your system with yum package manager.

yum install postgresql10-server postgresql10

Step 3 – Initialize PGDATA

After installing PostgreSQL server, It’s required to initialize it before using the first time. To initialize database use below command.

/usr/pgsql-10/bin/postgresql-10-setup initdb

Above command will take some time to initialize PostgreSQL first time. PGDATA environment variable contains the path of data directory.

PostgreSQL data directory Path: /var/lib/pgsql/10/data/

Setp 4 – Start PostgreSQL Server

To start PostgreSQL service using the following command as per your operating systems. Also, enable PostgreSQL service to autostart on system boot.

For CentOS/RHEL 7 and Fedora

systemctl start postgresql-10.service
systemctl enable postgresql-10.service

For CentOS/RHEL 6

service postgresql-10 start
chkconfig postgresql-10 on
Step 5 – Verify PostgreSQL Installation

After completing above steps, you have installed PostgreSQL 10 on your server, Let’s log in to postfix to verify that installation completed successfully.

su - postgres -c "psql"

psql (10.0)
Type "help" for help.
postgres=#

You may create a password for user postgres for security purpose.

postgres=# \password postgres

Congratulation’s! You have successfully installed PostgreSQL Server. Read below article to install phpPgAdmin.

How to Install phpPgAdmin on CentOS using Yum

Thanks for using this tutorial for installing PostgreSQL 10 on CentOS/RHEL 7/6 and Fedora 28/27/26 systems.

The post How to Install PostgreSQL on CentOS/RHEL 7 appeared first on TecAdmin.

]]>
https://tecadmin.net/install-postgresql-server-centos/feed/ 15
FATAL: Ident authentication failed for user "postgres" https://tecadmin.net/fatal-ident-authentication-failed-for-user-postgres/ https://tecadmin.net/fatal-ident-authentication-failed-for-user-postgres/#comments Mon, 09 Feb 2015 07:06:29 +0000 https://tecadmin.net/?p=7753 While configuring a new hosting setup with ROR and PostgreSQL. I faced following issue when application tried to connect postgres database server. Error:- FATAL: Ident authentication failed for user “postgres” Solution:- First I set the the password for postgres user in PostgreSQL using following commands. $ sudo -u postgres psql Now set the password using [...]

The post FATAL: Ident authentication failed for user "postgres" appeared first on TecAdmin.

]]>
While configuring a new hosting setup with ROR and PostgreSQL. I faced following issue when application tried to connect postgres database server.

Error:-

FATAL: Ident authentication failed for user “postgres”

Solution:-

First I set the the password for postgres user in PostgreSQL using following commands.

$ sudo -u postgres psql

Now set the password using following command.

postgres=# password

Let’s create a new user account for your application using following command. Also crate a database with ownership of that account.

postgres=# create user "myappusr" with password '_password_';
postgres=# create database "myapp_development" owner "myappusr";

Now edit pg_hba postgresql configuration file and update configuration. By default PostgreSQL uses IDENT-based authentication. You need to allow username and password based authentication. IDENT will never allow you to login via -U and -W options.

# vim /var/lib/pgsql/9.4/data/pg_hba.conf
local   all             postgres                                trust
local   all             myapp_usr                               trust
# IPv4 local connections:
host    all             all             127.0.0.1/32            trust
# IPv6 local connections:
#host    all             all             ::1/128                 trust

The post FATAL: Ident authentication failed for user "postgres" appeared first on TecAdmin.

]]>
https://tecadmin.net/fatal-ident-authentication-failed-for-user-postgres/feed/ 2
How to Find PostgreSQL Database Size https://tecadmin.net/check-database-and-table-size-in-postgresql/ https://tecadmin.net/check-database-and-table-size-in-postgresql/#comments Tue, 20 Jan 2015 04:38:11 +0000 https://tecadmin.net/?p=7104 This tutorial will help you to determine database size and table size in the PostgreSQL server. First login to your server using the command line and connect to the PostgreSQL server. Now you can use the following commands to determine the sizes of databases and tables in PostgreSQL. 1. Check PostgreSQL Database Size (Query) Use [...]

The post How to Find PostgreSQL Database Size appeared first on TecAdmin.

]]>
This tutorial will help you to determine database size and table size in the PostgreSQL server.

First login to your server using the command line and connect to the PostgreSQL server. Now you can use the following commands to determine the sizes of databases and tables in PostgreSQL.

1. Check PostgreSQL Database Size (Query)

Use the following commands to determine PostgreSQL database size using a query. First, open a shell and connect to the Postgres terminal.

sudo -u postgres psql 

Then use inbuild function pg_database_size() to find database size in PostgreSQL server.

postgres=# SELECT pg_database_size('mydb');

Check PostgreSQL Database Size

You can also use pg_size_pretty() function along with above to determine database size in human readable format like KB, MB, and GB etc.

postgres=# SELECT pg_size_pretty(pg_database_size('mydb'));

Check Postgres Database Size in MB, GB

2. Check PostgreSQL Database Size with pgAdmin

The pgAdmin users can also determine the size from the interface.

First login to the pgAdmin3 interface. Select your database and open statics tab. Here you can find the Size of your database as shown in below image:

pgAdmin calculate postgres database size

3. How to Find Table Size in PostgreSQL

Connect to the target database first with the following command:

postgres=# \c mydb;

Now calculate the table size in Postgres server using pg_total_relation_size() inbuilt function with human readable format.

mydb=# SELECT pg_size_pretty(pg_total_relation_size('employee'));

Calculate table size in postgresql

Concusion

This tutorial helps you to find database size in the PostgreSQL server. Also, provide you details to calculate table size in a database.

The post How to Find PostgreSQL Database Size appeared first on TecAdmin.

]]>
https://tecadmin.net/check-database-and-table-size-in-postgresql/feed/ 1
How To List Databases and Tables in PostgreSQL https://tecadmin.net/list-all-databases-and-tables-in-postgresql/ https://tecadmin.net/list-all-databases-and-tables-in-postgresql/#respond Tue, 20 Jan 2015 04:24:53 +0000 https://tecadmin.net/?p=7085 While working with PostgreSQL database servers, there is much useful application available for administering databases like pgAdmin4, phpPgAdmin, and SQL Workbench. A Postgres process contains multiple databases and is stored in a separate set of files under the server’s data directory. The Postgres server also comes with psql utility for database administration via command-line. This [...]

The post How To List Databases and Tables in PostgreSQL appeared first on TecAdmin.

]]>
While working with PostgreSQL database servers, there is much useful application available for administering databases like pgAdmin4, phpPgAdmin, and SQL Workbench. A Postgres process contains multiple databases and is stored in a separate set of files under the server’s data directory.

The Postgres server also comes with psql utility for database administration via command-line. This article will help you to how to list databases in PostgreSQL server along with all tables in a single database.

Listing Databases in PostgreSQL

First connect to PostgreSQL terminal with psql command as user “postgres”. The default installation doesn’t require any password until specified manually. You can execute sudo command as below to directly connect to psql terminal as postgres user:

sudo -u postgres psql 

Once you are connected to the psql terminal, type \l to list all available databases.

postgres=# \l
Output:
List of databases Name | Owner | Encoding | Collate | Ctype | Access privileges -----------+----------+----------+---------+-------+----------------------- postgres | postgres | UTF8 | en_IN | en_IN | myDatabase| tecadmin | UTF8 | en_IN | en_IN | =CTc/tecadmin + | | | | | tecadmin=CTc/tecadmin template0 | postgres | UTF8 | en_IN | en_IN | =c/postgres + | | | | | postgres=CTc/postgres template1 | postgres | UTF8 | en_IN | en_IN | =c/postgres + | | | | | postgres=CTc/postgres (4 rows)

You can also use \list to find similar results, but to find extended details use \l+\list+.

postgres=# \list+

With this command, you will find the additional details of the PostgreSQL database like size, tablespace, and description.

The postgres also provides an traditional SQL like statement to show all databases in Postgres. To determine the set of existing databases, fetch records from the pg_database system catalog, for example:

postgres=# SELECT datname FROM pg_database;
Output:
datname ----------- postgres template1 template0 myDatabase (4 rows)

Listing Tables in Postgres Database

To list tables of any database first you connect to that database and then view tables in that database. The first command will connect you with the database (example: myDatabase) to which you want to see tables:

postgres=# \c myDatabase

Once you’ve connected to a database, you will see the database name in the prompt. Then execute the \dt meta-command to list all the tables in current database.

myDatabase=# \dt
Output:
List of relations Schema | Name | Type | Owner --------+------------+-------+---------- public | results | table | tecadmin public | roles | table | tecadmin public | employee | table | tecadmin public | users | table | tecadmin (4 rows)

Conclusion

In this quick guide, you have learned to list databases in the PostgreSQL database server. Also found instructions to connect the database and list available tables in the database.

The post How To List Databases and Tables in PostgreSQL appeared first on TecAdmin.

]]>
https://tecadmin.net/list-all-databases-and-tables-in-postgresql/feed/ 0
How to Install PostgreSQL 9.6 on CentOS/RHEL 7 https://tecadmin.net/install-postgresql-on-centos-rhel-and-fedora/ https://tecadmin.net/install-postgresql-on-centos-rhel-and-fedora/#comments Sat, 10 Jan 2015 03:43:47 +0000 https://tecadmin.net/?p=2985 PostgreSQL is an open source object-relational, highly scalable, SQL compliant database management system. PostgreSQL is developed at the University of California at Berkeley Computer Science Department. This article will help you for installing PostgreSQL on CentOS, RHEL and Fedora Systems. Adding PostgreSQL Yum Repository The first step is to install PostgreSQL repository in your system, [...]

The post How to Install PostgreSQL 9.6 on CentOS/RHEL 7 appeared first on TecAdmin.

]]>
PostgreSQL is an open source object-relational, highly scalable, SQL compliant database management system. PostgreSQL is developed at the University of California at Berkeley Computer Science Department. This article will help you for installing PostgreSQL on CentOS, RHEL and Fedora Systems.

Adding PostgreSQL Yum Repository

The first step is to install PostgreSQL repository in your system, Use one of below commands as per your system architecture and operating system.

### CentOS/RHEL 7 ###
rpm -Uvh http://yum.postgresql.org/9.6/redhat/rhel-7-x86_64/pgdg-redhat96-9.6-3.noarch.rpm

### CentOS/RHEL 6 ###
rpm -Uvh http://yum.postgresql.org/9.6/redhat/rhel-6-x86_64/pgdg-redhat96-9.6-3.noarch.rpm


### Fedora 26 ###
rpm -Uvh http://yum.postgresql.org/9.6/fedora/fedora-26-x86_64/pgdg-fedora96-9.6-3.noarch.rpm

### Fedora 25 ###
rpm -Uvh http://yum.postgresql.org/9.6/fedora/fedora-25-x86_64/pgdg-fedora96-9.6-3.noarch.rpm

### Fedora 24 ###
rpm -Uvh http://yum.postgresql.org/9.6/fedora/fedora-25-x86_64/pgdg-fedora96-9.6-3.noarch.rpm

For more details visit PostgreSQL repositories link page where you can get repository package rpm for various operating systems.

Installing PostgreSQL Server

After enabling PostgreSQL yum repository in your system use following command to install PostgreSQL 9.6 on your system with yum package manager.

yum install postgresql96-server postgresql96
Initializing PGDATA

After installing PostgreSQL server, It’s required to initialize it before using the first time. To initialize database use below command.

/usr/pgsql-9.6/bin/postgresql96-setup initdb

Above command will take some time to initialize PostgreSQL first time. PGDATA environment variable contains the path of the data directory.

PostgreSQL data directory Path: /var/lib/pgsql/9./data/

Start PostgreSQL Server

To start PostgreSQL service using the following command as per your operating systems. Also, enable PostgreSQL service to autostart on system boot.

For CentOS/RHEL 7 and Fedora

systemctl start postgresql-9.6
systemctl enable postgresql-9.6

For CentOS/RHEL 6

service  postgresql-9.6 start
chkconfig postgresql-9.6 on
Verify PostgreSQL Installation

After completing above steps, you have installed PostgreSQL 9.6 on your server, Let’s log in to postfix to verify that installation completed successfully.

su - postgres

Use psql command to access PostgreSQL prompt with admin privileges.

 psql


psql (9.6.6)
Type "help" for help.

postgres=#

You may create password for user postgres for security purpose.

postgres=# password postgres

Congratulation’s! You have successfully installed PostgreSQL Server. Read below article to install phpPgAdmin.

How to Install phpPgAdmin on CentOS using Yum

Thanks for using this tutorial for installing PostgreSQL 9.6 on CentOS/RHEL 7/6 and Fedora 26/25/24 systems

The post How to Install PostgreSQL 9.6 on CentOS/RHEL 7 appeared first on TecAdmin.

]]>
https://tecadmin.net/install-postgresql-on-centos-rhel-and-fedora/feed/ 5