CENG301 DBMS - Session-5
CENG301 DBMS - Session-5
Session-5
Asst. Prof. Mustafa YENIAD
[email protected]
PostgreSQL GUI Tool pgAdmin by using docker
• Firstly, docker doemon have to be installed from the previous session.
• After that type the following:
$ docker run --name pgagmin4-web \
-p 5050:80 \
--restart always \
-e "[email protected]" \
DBMS
-e "PGADMIN_DEFAULT_PASSWORD=admin" \
-d dpage/pgadmin4
PostgreSQL settings: allow remote connections - Step-1
• Do not try the following steps on a live system unless you know what you are doing!
• Configuring PostgreSQL for remote connections is essential for accessing data from different
locations. By default, PostgreSQL only allows connections from the local machine, which can be a
limitation in many situations.
• Remote access to a PostgreSQL database is necessary for applications that require accessing the
data from different geographical locations or for teams that are working in different parts of the
world. It can also be crucial for troubleshooting issues that cannot be resolved locally or when the
DBMS
• Edit the postgresql.conf file* (in different systems it is located in different place. I usually search
for it) you can find its location by typing:
$ sudo find / -name "postgresql.conf"
• Open postgresql.conf file, uncomment and edit this line: listen_addresses = 'localhost'
• to: listen_addresses = '*'
• Important information:
DBMS
• Authentication methods (also new additonal methods are available upon the postgres versions):
• trust: the least secure authentication, essentially no password is needed!
• md5: very common, requires an md5-encrypted password to connect.
• ident: Uses pg_ident.conf file to check whether the OS account of the user trying to connect has a mapping
to a PostgreSQL account. The password is not checked. ident is not available on Windows.
• peer: Uses the OS name of the user from the kernel. It is available only for Linux, FreeBSD, macOS, and
Solaris, and only for local connections on these systems.
• cert: The client must have a registered certificate. cert uses an ident file such as pg_ident to map the
certificate to a PostgreSQL user.
• Connect to PostgreSQL database server and change the password of the postgres user:
$ sudo --login -u postgres
• Login to postgres shell and set a new password for postgres user:
postgres@[hostname]:~ $ psql
• After opening the session, register a new Server (your host) and test a new Connection.
PostgreSQL Important Actions (create a new db, user and set permissions)
• Now, create a new database named dvdental:
postgres=# CREATE DATABASE dvdrental;
• Create a new user named myuser: (or any username you desire)
postgres=# CREATE USER myuser PASSWORD 'new_password';
• Set all permissions to myuser for dvdrental database:
DBMS
• All these steps can also be applied easily by using pgAdmin tool.
PostgreSQL Important Actions (import / restore a db dump file i.e. from backup)
• Using shell is always recommended when import (especially huge) db-dump files.
• Firstly, download dump (dvdrental.zip) file provided in Aybuzem.
• Then, move (mv) or copy (cp) it to postgres user's home directory (/var/lib/pgsql).
$ sudo cp ~/Downloads/dvdrental.zip /var/lib/pgsql/
• Connect to postgres user environment, extract the archive file, list the directory contents and go to db shell
: --login -u postgres
$ sudo
DBMS
• Finally import the db tape archive .tar (dvdental.tar) into PostgreSQL service:
postgres@[hostname]:~ $ pg_restore -U postgres -d dvdrental dvdrental.tar
PostgreSQL Important Actions
• Open the postgres shell and check the status:
postgres@[hostname]:~ $ psql
• Show / list all databases:
postgres=# \l
postgres=# \l+
DBMS
postgres=# \list