DEV Community

Pawan Kukreja
Pawan Kukreja

Posted on

Architecture of PostgreSQL.

Architecture Fundamentals

In database jargon, PostgreSQL uses a client/server model. A PostgreSQL session consists of the following cooperating processes:

  • A server process, which manages the database files, accepts connections to the database from client applications, and performs database actions on behalf of the clients. The database server program is called postgres.

  • The user's client application that wants to perform database operations. Client applications can be very diverse in nature: a client could be a text-oriented tool, a graphical application, a web server that accesses the database to display web pages, or a specialized database maintenance tool. Some client applications are supplied with the PostgreSQL distribution; most are developed by users.

As is typical of client/server applications, the client and the server can be on different hosts. In that case
they communicate over a TCP/IP network connection. You should keep this in mind, because the files that can be accessed on a client machine might not be accessible on the database server machine.

The PostgreSQL server can handle multiple concurrent connections from clients. To achieve this it starts
(“forks”) a new process for each connection. From that point on, the client and the new server process
communicate without intervention by the original postgres process. Thus, the supervisor server process
is always running, waiting for client connections, whereas client and associated server processes come and
go.

Creating a Database

The first test to see whether you can access the database server is to try to create a database. A running
PostgreSQL server can manage many databases.

To create a new database, in this example named mydb, you use the following command:

`createdb mydb`
Enter fullscreen mode Exit fullscreen mode

If this produces no response then this step was successful and you can skip over the remainder of this
section.

If you see a message similar to:
createdb: command not found

then PostgreSQL was not installed properly. Either it was not installed at all or your shell's search path
was not set to include it. Try calling the command with an absolute path instead:

/usr/local/pgsql/bin/createdb mydb
Enter fullscreen mode Exit fullscreen mode

The path at your site might be different. Contact your site administrator or check the installation instructions to correct the situation.

Another response could be this:
createdb: error: connection to server on socket "/tmp/.s.PGSQL.5432"
failed: No such file or directory
Is the server running locally and accepting connections on
that socket?

This means that the server was not started, or it is not listening where createdb expects to contact it.
Again, check the installation instructions or consult the administrator.

Another response could be this:

createdb: error: connection to server on socket "/tmp/.s.PGSQL.5432"
failed: FATAL: role "pawan" does not exist

where your own login name mentioned. This will happen if the administrator has not created a PostgreSQL user account for you.

If you have a user account but it does not have the privileges required to create a database, you will see
the following:
createdb: error: database creation failed: ERROR: permission denied
to create database

If PostgreSQL refuses to create databases for
you then the site administrator needs to grant you permission to create databases.

You can also create databases with other names. PostgreSQL allows you to create any number of databases
at a given site.

createdb
Enter fullscreen mode Exit fullscreen mode

If you do not want to use your database anymore you can remove it.

dropdb mydb
Enter fullscreen mode Exit fullscreen mode

Top comments (0)