PostgreSQL Tutorial

  • Home
  • Stored Procedures
  • Triggers
  • Views
  • Interfaces
    • PostgreSQL PHP
    • PostgreSQL Python
    • PostgreSQL JDBC
  • Functions
    • Aggregate Functions
    • Date / Time Functions
    • String Functions
    • Math Functions
Home / PostgreSQL Tutorial / Connect To a PostgreSQL Database

Connect To a PostgreSQL Database

Summary: in this tutorial, we will show you different ways to connect to PostgreSQL database using an interactive terminal program called psql and pgAdmin GUI application.

When you installed PostgreSQL database server, the PostgreSQL installer also installed some useful tools for working with the database server. You can connect to the PostgreSQL database server by using the psql or pgAdmin tool.

Connect to PostgreSQL database using psql

psql is an interactive terminal program provided by PostgreSQL. You can do a lot with psql tool e.g., execute SQL statements, manage database objects, etc.

The following steps show you how to connect to the PostgreSQL database server by using the psql program:

First launch psql program.

Second, enter all the required information such as the server, database, port, username, and password. If you press enter, psql will use default values inside the square brackets.

Third, you can interact with PostgreSQL database server by using various SQL statements. You can try the following statement to test it out:

1
SELECT version();

psql tool

Please do not forget to put the semicolon (;) at the end of the statement. After pressing enter, psql will give you the current PostgreSQL version that you have in the system.

Connect to PostgreSQL database using pgAdmin GUI application

The second way to connect to a database is using pgAdmin GUI application. By using pgAdmin GUI application, you can interact with PostgreSQL database server via an intuitive user interface.

The following illustrates how to connect to a database using pgAdmin GUI application:

First, launch the pgAdmin application.

Launch pgAdmin

Second, double-click the PostgreSQL 9.2 under the Servers item. pgAdmin will ask you for the password. You have to provide the password for the postgres user. Once finish, click OK button to log in to the PostgreSQL server.

pgAdmin Enter Password

Third, choose the postgres database and click  Execute Arbitrary SQL queries tool from the pgAdmin’s toolbar.

Launch SQL editor
Fourth, enter the following statement:

Execute SQL query

Fifth, click the execute query button in the toolbar, pgAdmin will display the result in the output panel.

pgadmin output

Connect to PostgreSQL database from other applications

Any application that supports ODBC or JDBC can connect to PostgreSQL database server. In addition, if you develop an application that uses an appropriate driver, the application can connect to the PostgreSQL database server as well.

In this tutorial, you’ve learned how to connect to PostgreSQL database server by using different client tools including psql and pgAdmin GUI application. Let’s explore the PostgreSQL database objects and find out how can we use them in our applications.

Related Tutorials

  • PostgreSQL PHP: Connect to PostgreSQL Database Using PDO
  • PostgreSQL Python: Connect To PostgreSQL Database Server
Previous Tutorial: Load PostgreSQL Sample Database
Next Tutorial: PostgreSQL Server and Database Objects

PostgreSQL Quick Start

  • What is PostgreSQL?
  • Install PostgreSQL
  • Connect to Database
  • Download PostgreSQL Sample Database
  • Load Sample Database
  • Explore Server and Database Objects

PostgreSQL Fundamentals

  • PostgreSQL Select
  • PostgreSQL Order By
  • PostgreSQL Select Distinct
  • PostgreSQL Where
  • PostgreSQL LIMIT
  • PostgreSQL IN
  • PostgreSQL Between
  • PostgreSQL Like
  • PostgreSQL Inner Join
  • PostgreSQL Left Join
  • PostgreSQL Full Outer Join
  • PostgreSQL Cross Join
  • PostgreSQL Natural Join
  • PostgreSQL Group By
  • PostgreSQL Having
  • PostgreSQL Union
  • PostgreSQL Intersect
  • PostgreSQL Except
  • PostgreSQL Subquery
  • PostgreSQL Insert
  • PostgreSQL Update
  • PostgreSQL Delete

Managing Table Structure

  • PostgreSQL Data Types
  • PostgreSQL Create Table
  • PostgreSQL Alter Table
  • PostgreSQL Drop Table
  • PostgreSQL Truncate Table
  • PostgreSQL CHECK Constraint
  • PostgreSQL Not-Null Constraint
  • PostgreSQL Foreign Key
  • PostgreSQL Primary Key
  • PostgreSQL UNIQUE Constraint

PostgreSQL Views

  • Managing PostgreSQL Views
  • Creating Updatable Views
  • PostgreSQL Materialized Views
  • The WITH CHECK OPTION Views
  • PostgreSQL Recursive View

PostgreSQL Triggers

  • Introduction to Trigger
  • Creating A Trigger
  • Managing PostgreSQL Triggers

About PostgreSQL Tutorial

PostgreSQLTutorial.com is a website dedicated to developers and database administrators who are working on PostgreSQL database management system.

We constantly publish useful PostgreSQL tutorials to keep you up-to-date with the latest PostgreSQL features and technologies. All PostgreSQL tutorials are simple, easy-to-follow and practical.

Recent PostgreSQL Tutorials

  • PostgreSQL ANY Operator
  • PostgreSQL EXISTS
  • How To Delete Duplicate Rows in PostgreSQL
  • PostgreSQL TO_CHAR Function
  • PostgreSQL TO_NUMBER Function
  • PostgreSQL TO_TIMESTAMP Function
  • PostgreSQL CEIL Function
  • PostgreSQL MOD Function
  • PostgreSQL FLOOR Function
  • PostgreSQL ABS Function

More Tutorials

  • PostgreSQL Cheat Sheet
  • PostgreSQL Administration
  • PostgreSQL PHP
  • PostgreSQL Python
  • PostgreSQL JDBC
  • PostgreSQL Resources

Site Info

  • Home
  • About Us
  • Contact Us
  • Privacy Policy

Copyright © 2017 by PostgreSQL Tutorial Website. All Rights Reserved.