Free Hosting Online for WorkStations

< Previous | Contents | Next >

Creating Users and Databases‌


The createuser command adds a new user and dropuser removes one. Likewise, the createdb command adds a new database and dropdb removes one. Each of these commands have their own manual pages but we will discuss some of the options here. Each command acts on the default cluster (running on port 5432) but you can pass --port=port to modify users and databases of an alternate cluster.

These commands must connect to the PostgreSQL server to do their job and they must be authenti- cated as a user with sufficient privileges to be able to execute the specified operation. The easiest way to achieve this is to use the postgres Unix account and connect over the file-based socket:


# su - postgres

$ createuser -P king_phisher Enter password for new role: Enter it again:

$ createdb -T template0 -E UTF-8 -O king_phisher king_phisher

$ exit

# su - postgres

$ createuser -P king_phisher Enter password for new role: Enter it again:

$ createdb -T template0 -E UTF-8 -O king_phisher king_phisher

$ exit


In the example above, the -P option asks createuser to query for a password once it creates the new king_phisher user. Looking at the createdb command, the -O defines the user owning the new database (which will thus have full rights to create tables and grant permissions and so on). We also want to be able to use Unicode strings, so we add the -E UTF-8 option to set the encoding, which in turn requires us to use the -T option to pick another database template.

We can now test that we can connect to the database over the socket listening on localhost (-h localhost) as the king_phisher user (-U king_phisher):


# psql -h localhost -U king_phisher king_phisher

Password for user king_phisher: psql (9.5.2)

SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256,

compression: off) Type ”help” for help.


king_phisher=>

# psql -h localhost -U king_phisher king_phisher

Password for user king_phisher: psql (9.5.2)

SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256,

compression: off) Type ”help” for help.


king_phisher=>

As you can see, the connection was successful.


Top OS Cloud Computing at OnWorks: