PostgreSQL Print

  • 148

What Is PostgreSQL?

PostgreSQL is pronounced Post-Gres-Q-L, also called just Postgres.

PostgreSQL is an object-relational database system that has the features of traditional commercial database systems with enhancements to be found in next-generation DBMS systems. PostgreSQL is free and the complete source code is available.

PostgreSQL development is performed by a team of mostly volunteer developers spread throughout the world and communicating via the Internet.

Find Our More About PostgreSQL

How To Create A Database

First you will need to contact us and request to setup a User. Only one database per User, so if you need more databases, just request another setup of a User.

  1. Login with your account username and password to phpPgAdmin. ( - the url will be provided to you via email)
  2. From the menu in the left frame click on the 'PostgreSQL' link.
  3. In the right frame click on 'Create database'.
  4. For the name of database enter your username and select an encoding.
  5. Click on 'Create' button to create the database.
    Please remember that currently your account has been set up such that you can only create one database. Any attempt to create more will result in errors.
  6. From the menu in the left frame click on newly created database.
  7. Make a selection from the list and proceed.

How To Connect To PostgreSQL via JSP:

First you need to import the JDBC Driver

import java.sql.*;

Loading the Driver:

In the first method, your code implicitly loads the driver using the Class.forName() method. For PostgreSQL, you would use:


Connecting to the Database:

With JDBC, a database is represented by a URL (Uniform Resource Locator). With PostgreSQL, this takes one of the following forms:


The parameters have the following meanings:
host == The host name of the server. Defaults to localhost. To specify an IPv6 address your must enclose the host parameter with square brackets, for example:

port = The port number the server is listening on. Defaults to the PostgreSQL standard port number (5432).

database = The database name.

To connect, you need to get a Connection instance from JDBC. To do this, you use the DriverManager.getConnection() method:

Connection db = DriverManager.getConnection(url, username, password);

Closing the Connection

To close the database connection, simply call the close() method to the Connection:


The above is taken from the PostgreSQL documentation. For more information please refer to the documentation at

How To Connect to PostgreSQL via PHP

You'll want to use pg_connect(), it opens a connection to a PostgreSQL database specified by the connection_string. It returns a connection resource on success. It returns FALSE if the connection could not be made. connection_string should be a quoted string.

Some Examples:

$dbconn = pg_connect("dbname=mary");
//connect to a database named "mary"

$dbconn2 = pg_connect("host=localhost port=5432 dbname=mary");
// connect to a database named "mary" on "localhost" at port "5432"
$dbconn3 = pg_connect("host=sheep port=5432 dbname=mary user=lamb password=foo"); //connect to a database named "mary" on the host "sheep" with a username and password
$conn_string = "host=sheep port=5432 dbname=test user=lamb password=bar"; $dbconn4 = pg_connect($conn_string); //connect to a database named "test" on the host "sheep" with a username and password

You can find more information about this at

Was this answer helpful?

« Back