Answer Key To Lab Exercises
Answer Key To Lab Exercises
Lab Exercise 1
• Choose the platform on which you want to install PostgreSQL
• Download PostgreSQL one-click installer from EnterpriseDB website for
chosen platform
• Prepare the platform for installation
• Install PostgreSQL
• Connect to PostgreSQL using psql
Answer:
Windows 7 64-bit Installation
• Login as administrative user.
• Go to www.enterprisedb.com and download PostgreSQL 9.3 binaries:
• http://www.enterprisedb.com/downloads/postgres-postgresql-
downloads
• Run the binaries:
• Click yes on the User Control security dialog box and PostgreSQL
installation wizard will appear
• Follow the steps in the wizard and install PostgreSQL. Look at following
snapshots for further information:
• Maximum time to complete client authentication will be 10 seconds
Answer:
• Open a terminal:
[root@localhost ~]# su - postgres
[postgres@localhost ~]$ vi /opt/PostgreSQL/9.3/data/postgresql.conf
Lab Exercise 2
• Working as a DBA is a challenging job and to track down certain activities
on the database server logging has to be implemented. Go through server
parameters that control logging and implement following:
• Save all the error message in a file inside pg_log folder in your cluster data
directory (e.g. c:\edbdata)
• Log all queries and their time which are taking more than 5 seconds to
execute
• Log the users who are connecting to the database cluster
• Make above changes and verify them
Answer:
• Open a terminal:
[root@localhost ~]# su - postgres
[postgres@localhost ~]$ vi /opt/PostgreSQL/9.3/data/postgresql.conf
postgres=# \q
[postgres@localhost ~]$
Lab Exercise 3
• Perform following changes recommended by a senior DBA and verify
them:
• Shared buffer to 256MB
• Effective Cache for indexes to 512MB
• Maintenance memory to 64MB
• Temporary memory to 8MB
Answer:
• Open a terminal:
[root@localhost ~]# su - postgres
[postgres@localhost ~]$ vi /opt/PostgreSQL/9.3/data/postgresql.conf
Lab Exercise 4
• Vacuuming is important maintenance and need to be properly configured.
Change following autovacuum parameter on the production server:
• Autovacuum workers to 6
• Auto Vacuum threshhold to 100
• Auto Vacuum scale factor to 0.3
• Auto Analyze threshhold to 100
• Auto vacuum cost limit to 100
Answer:
• Open a terminal:
[root@localhost ~]# su - postgres
[postgres@localhost ~]$ vi /opt/PostgreSQL/9.3/data/postgresql.conf
Lab Exercise 2
• An e-music online store website application developer wants to add
online buy/sell facility and has asked you to separate all tables used in
online transactions, here you have suggested to use schemas. Implement
following suggested options:
• Create an ebuy user with password ‘lion’
• Create an ebuy schema which can be used by ebuy user
• Login as ebuy user, create a table sample1 and check whether that table
belongs to ebuy schema or not.
Answer:
• Open a Terminal and connect to postgres database with postgres user:
[postgres@localhost ~]$ /opt/PostgreSQL/9.3/bin/psql postgres postgres
Password for user postgres:
psql.bin (9.3.3)
Type "help" for help.
postgres=# create user ebuy password 'lion';
CREATE ROLE
postgres=# create schema ebuy authorization ebuy;
CREATE SCHEMA
postgres=# \c postgres ebuy
Password for user ebuy:
• Open a Terminal and copy the edbstore.sql file into home directory of
postgres user.
[root@localhost ~]# cp /home/edb/Downloads/edbstore.sql
/home/postgres/
[root@localhost ~]# chown postgres:postgres
/home/postgres/edbstore.sql
[root@localhost ~]# su - postgres
Run following command:
[postgres@localhost ~]$ /opt/PostgreSQL/9.3/bin/psql -f edbstore.sql -d
edbstore -U edbstore
Password for user edbstore:
edbstore=> \dt
List of relations
Schema | Name | Type | Owner
----------+------------+-------+----------
edbstore | categories | table | edbstore
edbstore | cust_hist | table | edbstore
edbstore | customers | table | edbstore
edbstore | dept | table | edbstore
edbstore | emp | table | edbstore
edbstore | inventory | table | edbstore
edbstore | job_grd | table | edbstore
edbstore | jobhist | table | edbstore
edbstore | locations | table | edbstore
edbstore | orderlines | table | edbstore
edbstore | orders | table | edbstore
edbstore | products | table | edbstore
edbstore | reorder | table | edbstore
(13 rows)
edbstore=> \dv
List of relations
Schema | Name | Type | Owner
----------+----------+------+----------
edbstore | salesemp | view | edbstore
(1 row)
edbstore=> \df
List of functions
Schema | Name | Result data type | Argument data types | Type
--------+------+------------------+---------------------+------
(0 rows)
edbstore=> \ds
List of relations
Schema | Name | Type | Owner
----------+--------------------------+----------+----------
edbstore | categories_category_seq | sequence | edbstore
edbstore | customers_customerid_seq | sequence | edbstore
edbstore | next_empno | sequence | edbstore
edbstore | orders_orderid_seq | sequence | edbstore
edbstore | products_prod_id_seq | sequence | edbstore
(5 rows)
edbstore=>
Lab Exercise 4
• Retrieve a list of databases using SQL Query
• Retrieve a list of databases using psql meta command.
• Retrieve a list of tables in edbstore database and check which schema and
owner they have.
Answer:
• Connect to edbstore and execute following commands:
[postgres@localhost ~]$ /opt/PostgreSQL/9.3/bin/psql -d edbstore -U
edbstore
Password for user edbstore:
psql.bin (9.3.3)
Type "help" for help.
edbstore=> select datname from pg_database;
datname
-----------
template1
template0
postgres
edbstore
(4 rows)
edbstore=> \l
edbstore=> \dt
List of relations
Schema | Name | Type | Owner
----------+------------+-------+----------
edbstore | categories | table | edbstore
edbstore | cust_hist | table | edbstore
edbstore | customers | table | edbstore
edbstore | dept | table | edbstore
edbstore | emp | table | edbstore
edbstore | inventory | table | edbstore
edbstore | job_grd | table | edbstore
edbstore | jobhist | table | edbstore
edbstore | locations | table | edbstore
edbstore | orderlines | table | edbstore
edbstore | orders | table | edbstore
edbstore | products | table | edbstore
edbstore | reorder | table | edbstore
(13 rows)
edbstore=> \q
Module 6:
Lab Exercise – 1
• Connect to database using psql
• Switch databases.
• Describe the customers table.
• Describe the customers table including description.
• List all databases.
• List all schemas.
• List all tablespaces.
• Execute an sql statement, saving the output to a file.
• Do the same thing, just saving data, not the column headers.
• Create a script via another method, and execute from psql.
• Turn on the expanded table formatting mode.
• Lists tables, views and sequences with their associated access privileges.
• Which meta command display SQL text for a function?
• View the current working directory.
Answer:
[postgres@localhost ~]$ /opt/PostgreSQL/9.3/bin/psql postgres postgres
Password for user postgres:
psql.bin (9.3.3)
Type "help" for help.
edbstore=> \d customers
edbstore=>\l
edbstore=>\dn
edbstore=>\db
edbstore=> \o customer_data.txt
edbstore=> select * from customers;
edbstore=> \o
edbstore=> \t
Showing only tuples.
edbstore=> \o customer_data.txt
edbstore=> select * from customers;
edbstore=> \o
edbstore=> \t
Tuples only is off.
edbstore=> \q
edbstore=> \dp
edbstore=> \df+
edbstore=> \! pwd
/home/postgres
edbstore=> \q
Module 7:
Lab Exercise - 1
• Open Pgadmin III and connect to the default PostgreSQL database cluster.
• Create a user named pguser.
• Create a database named pgdb owned by pguser.
• After creating pgdb database change its connection limit to 2.
• Create a schema named pguser inside pgdb database. Schema owner
should be pguser.
Continue to lab exercise 2
Answer:
Open Pgadmin III as shown in following snapshots:
Right Click on Login Roles and click New Login Role as show in snapshot:
Click Definition Tab:
Create a schema named pguser inside pgdb database. Schema owner should be
pguser.
Right Click on Schemas in pgdb database and click New Schema.
Now Enter Schema Name and Owner. Click ok.
Lab Exercise - 2
• You have created pgdb database with pguser schema. Create following
objects in pguser schema:
• Table: Teams with column TeamID, TeamName, TeamRatings
• Sequence: seq_teamid start value: 1 increment by 1
• Columns: Change default value for TeamID column to seq_teamid
• Constraint: TeamRatings must be between 1 and 10
• Index: Primary Key TeamID
• View: Display all teams in ascending order of their ratings. Name the view
as vw_top_teams
Answer:
Open Pgadmin III and Expland Databases --> pgdb --> Schemas --> pguser
Right Click Tables and click New Table. Enter Table name and Owner
Click on definition tab and Enter Increment: 1 and Start: 1. Click ok.
Expan teams table-- columns and right click on teamid column. Click Properties
Enter Definition for Check constraint. You may skip the name as it will be
assigned by DB Server.
Right Click on Views in pguser Schema. Click New View.
Enter the name and Owner of the view.
Click definition tab and enter the body of the view. Click ok
Lab Exercise - 3
• View all rows present in teams table.
• Using the Edit data window you just opened in previous step insert
following rows in teams table
TeamID TeamName TeamRatings
Auto generated Oilers 1
Auto generated Rangers 6
Auto generated Canucks 8
Auto generated Blackhawks 5
Auto generated Bruins 2
Answers:
• Make following Changes:
listen_addresses='*'
Lab Exercise - 2
• You are working as a PostgreSQL DBA. A developer showed you
following error:
psql: could not connect to server: Connection refused
(0x0000274D/10061)
Is the server running on host 192.168.30.22" and accepting
TCP/IP connections on port 5432?
Answer:
• Open a terminal:
[root@localhost ~]# su - postgres
[postgres@localhost ~]$ vi /opt/PostgreSQL/9.3/data/pg_hba.conf
Lab Exercise - 3
• A new developer has joined. His ID number is 89. Create a new user by
name dev89 and password ‘password89’. Then assign necessary privileges
to dev89 so that he can connect to the edbstore database and view all
tables.
Answer:
• Open a Terminal and login as postgres user:
[root@localhost ~]# su - postgres
[postgres@localhost ~]$ /opt/PostgreSQL/9.3/bin/psql postgres postgres
Password for user postgres:
psql.bin (9.3.3)
Type "help" for help.
edbstore=> \q
Lab Exercise - 4
A new developer joins e-music corp. He has ip address 192.168.30.89. He is not
able to connect from his machine to the PostgreSQL server and gets the following
error on the server
FATAL: no pg_hba.conf entry for host “1.1.1.89", user “dev89", database
“edbstore", SSL off
Configure your server so that the new developer can connect from his machine.
Answer:
• Open a terminal:
[root@localhost ~]# su - postgres
[postgres@localhost ~]$ vi /opt/PostgreSQL/9.3/data/pg_hba.conf
Module 9
Lab Exercise - 1
Test your knowledge:
1. Initiate an PSQL session
2. PSQL commands access the database.
True/False
3. The following SELECT statement executes successfully:
SELECT ename, job, sal AS Salary FROM emp;
True/False
4. The following SELECT statement executes successfully:
SELECT * FROM emp;
True/False
5. There are coding errors in the following statement. Can you identify
them?
Answer:
1. Open a Terminal and login as postgres. Execute following command to connect
to database using PSQL:
[root@localhost ~]# su - postgres
[postgres@localhost ~]$ /opt/PostgreSQL/9.3/bin/psql edbstore
edbstore
Password for user edbstore:
psql.bin (9.3.3)
Type "help" for help.
edbstore=>
2. True
5. Case sensitive Colum Headings and Column Headings with space muct be
enclosed in double quotes "
SELECT empno, ename, sal * 12 "ANNUAL SALARY"
FROM edbstore.emp;
Lab Exercise - 2
• Write a statement for following:
1. The HR department needs a report of all employees. Write a query to
display the name, department number, and department name for all
employees.
2. Create a report to display employees’ name and employee number along
with their manager’s name and manager number. Label the columns
Employee, Emp#, Manager, and Mgr#, respectively.
3. Create a report for the HR department that displays employee names,
department numbers, and all the employees who work in the same
department as a given employee. Give each column an appropriate label.
Answer:
Open a Terminal and login as postgres. Execute following command to connect
to database using PSQL:
[root@localhost ~]# su - postgres
[postgres@localhost ~]$ /opt/PostgreSQL/9.3/bin/psql edbstore
edbstore
Password for user edbstore:
psql.bin (9.3.3)
Type "help" for help.
edbstore=>
Execute following statemens:
1. edbstore=> select ename, emp.deptno, dname from emp join dept on
emp.deptno=dept.deptno;
3. edbstore=> select ename, deptno from emp where deptno = (select deptno
from emp where ename='SMITH');
Lab Exercise - 3
1. Write a query that displays the employee number and name of all
employees who work in a department with any employee whose name
contains a E.(use subquery)
Update and delete data in the EMP table.
2. Change the name of employee 7566 to Drexler.
3. Change the salary to $1,000 for all employees who have a salary less than
$900.
4. Verify your changes to the table.
5. Delete MILLER from the EMP table.
Answer:
Open a Terminal and login as postgres. Execute following command to connect
to database using PSQL:
[root@localhost ~]# su - postgres
[postgres@localhost ~]$ /opt/PostgreSQL/9.3/bin/psql edbstore
edbstore
Password for user edbstore:
psql.bin (9.3.3)
Type "help" for help.
edbstore=>
Execute following statemens:
1. edbstore=> select ename, deptno from emp where deptno IN (select deptno
from emp where ename like '%E%');
Lab Exercise - 4
• Create the EMP2 table based on the structure of the EMP table. Include
only the empno, ename, sal, and deptno columns. Name the columns in
your new table ID, FIRST_NAME, SALARY , and DEPTID, respectively.
• The staff in the HR department wants to hide some of the data in the EMP
table. They want a view called EMPVU based on the employee numbers,
employee names, and department numbers from the EMP table. They
want the heading for the employee name to be EMPLOYEE.
• Confirm that the view works. Display the contents of the EMPVU view.
• Using your EMPVU view, write a query for the SALES department to
display all employee names and department numbers.
Answer:
Open a Terminal and login as postgres. Execute following command to connect
to database using PSQL:
[root@localhost ~]# su - postgres
[postgres@localhost ~]$ /opt/PostgreSQL/9.3/bin/psql edbstore
edbstore
Password for user edbstore:
psql.bin (9.3.3)
Type "help" for help.
edbstore=>
Execute following statemens:
1. edbstore=> CREATE TABLE emp2(ID, FIRST_NAME, SALARY, DEPTID) AS
select empno, ename, sal, deptno from emp;
Lab Exercise - 5
You need a sequence that can be used with the primary key column of the dept
table. The sequence should start at 60 and have a maximum value of 200. Have
your sequence increment by 10. Name the sequence dept_id_seq.
To test your sequence, write a script to insert two rows in the dept table.
Create a index on deptno column of dept table.
Create and test a partial index.
Answer:
Open a Terminal and login as postgres. Execute following command to connect
to database using PSQL:
[root@localhost ~]# su - postgres
[postgres@localhost ~]$ /opt/PostgreSQL/9.3/bin/psql edbstore
edbstore
Password for user edbstore:
psql.bin (9.3.3)
Type "help" for help.
edbstore=>
edbstore=> \d cust_hist
Table "edbstore.cust_hist"
Column | Type | Modifiers
------------+---------+-----------
customerid | integer | not null
orderid | integer | not null
prod_id | integer | not null
Indexes:
"ix_cust_hist_customerid" btree (customerid)
Foreign-key constraints:
"fk_cust_hist_customerid" FOREIGN KEY (customerid) REFERENCES
customers(customerid) ON DELETE CASCADE
edbstore=>\q
Module 10
Lab Exercise - 1
• EDBStore website database is all setup and as a DBA you need to plan a
proper backup strategy and implement it.
• As the root user, create a folder /pgbackup and assign ownership to
Postgres user using chown utility or windows security tab in folder
properties.
• Take a full database dump of the edbstore database with the pg_dump
utility. The dump should be in plain text format.
• Name the dump file as edbstore_full.sql and store it in the /pgbackup
directory.
Answer:
Open a Terminal and login as postgres user:
Lab Exercise - 2
Take a dump edbstore schema from edbstore database and name the file as
edbstore_schema.sql,
Take a data-only dump of the edbstore database, disable all triggers for faster
restore, use the insert command instead of copy, and name the file as
edbstore_data.sql
Take a full dump of customers table and name the file as edbstore_customers.sql
Answer:
Open a Terminal and login as postgres user:
[postgres@localhost ~]$ /opt/PostgreSQL/9.3/bin/pg_dump -n
edbstore -f /pgbackup/edbstore_schema.sql -U postgres edbstore
Password:
Lab Exercise - 3
Take a full database dump of the edbstore in compressed format using the
pg_dump utility, name the file as edbstore_full_fc.dmp
Answer:
Open a Terminal and login as postgres user:
[postgres@localhost ~]$ /opt/PostgreSQL/9.3/bin/pg_dump -Fc -f
/pgbackup/edbstore_full_fc.dmp -U postgres edbstore
Password:
Lab Exercise - 4
In this exercise you will demonstrate your ability to restore a database.
Drop database edbstore.
Create database edbstore with owner edbstore
Restore the full dump from edbstore_full.sql and verify all the objects and their
ownership.
Drop database edbstore.
Create database edbstore with edbstore owner.
Restore the full dump from compressed file edbstore_full_fc.dmp and verify all
the objects and their ownership.
Answer:
Open a Terminal and login as postgres user:
[root@localhost ~]# su - postgres
[postgres@localhost ~]$ /opt/PostgreSQL/9.3/bin/dropdb edbstore
Password:
[postgres@localhost ~]$ /opt/PostgreSQL/9.3/bin/createdb -O edbstore
edbstore
Password:
[postgres@localhost ~]$ ls /pgbackup/
edbdata.sql edbstore_full_fc.dmp edbstore_schema.sql
edbstore_data.sql edbstore_full.sql
[postgres@localhost ~]$ /opt/PostgreSQL/9.3/bin/psql -f
/pgbackup/edbstore_full.sql -d edbstore -U edbstore
Password for user edbstore:
[postgres@localhost ~]$ /opt/PostgreSQL/9.3/bin/psql -d edbstore -U edbstore
Password for user edbstore:
psql.bin (9.3.3)
Type "help" for help.
edbstore=> \dt
List of relations
Schema | Name | Type | Owner
----------+------------+-------+----------
edbstore | categories | table | edbstore
edbstore | cust_hist | table | edbstore
edbstore | customers | table | edbstore
edbstore | dept | table | edbstore
edbstore | emp | table | edbstore
edbstore | emp2 | table | edbstore
edbstore | inventory | table | edbstore
.........
.........
edbstore=> \q
[postgres@localhost ~]$ /opt/PostgreSQL/9.3/bin/dropdb edbstore
Password:
[postgres@localhost ~]$ /opt/PostgreSQL/9.3/bin/createdb -O edbstore
edbstore Password:
[postgres@localhost ~]$ /opt/PostgreSQL/9.3/bin/pg_restore -d edbstore
/pgbackup/edbstore_full_fc.dmp
Password:
[postgres@localhost ~]$ /opt/PostgreSQL/9.3/bin/psql -d edbstore -U edbstore
Password for user edbstore:
psql.bin (9.3.3)
Type "help" for help.
edbstore=> \dt
List of relations
Schema | Name | Type | Owner
----------+------------+-------+----------
edbstore | categories | table | edbstore
edbstore | cust_hist | table | edbstore
edbstore | customers | table | edbstore
edbstore | dept | table | edbstore
edbstore | emp | table | edbstore
edbstore | emp2 | table | edbstore
.........
.........
Lab Exercise - 5
• Create a directory /opt/arch or c:\arch and give ownership to Postgres
user.
• Configure your cluster to run in archive mode and archive log location to
be /opt/arch or c:\arch.
• Take a full online base backup of your cluster in /pgbackup directory
using pg_basebackup utility.
Answer:
Lab Exercise - 6
• A database cluster can encounter different types of failures. Recover your
database from variety of simulated failures:
- Recover from loss of postgresql.conf file.
- Recover from loss of a emp table data file.
- Recover mistakenly dropped table cust_hist
Answer:
Recover from loss of postgresql.conf file.
Stop the database cluster:
[postgres@localhost ~]$ /opt/PostgreSQL/9.3/scripts/serverctl.sh stop
Now recreate the foreign key constraint and the deleted view.
edbstore=>
Module 11
Lab Exercise - 1
Create an explain plan for following query
Select * from emp where empno=7566;
Select * from emp where empno > 7566
Select * from emp where empno is not null
Answer:
Open a Terminal and login as postgres. Execute following command to connect
to database using PSQL:
[root@localhost ~]# su - postgres
[postgres@localhost ~]$ /opt/PostgreSQL/9.3/bin/psql edbstore
edbstore
Password for user edbstore:
psql.bin (9.3.3)
Type "help" for help.
edbstore=>
Lab Exercise - 2
In previous exercise you saw that first query is not using index scan:
edbstore=> explain select * from emp where empno=7566;
QUERY PLAN
-----------------------------------------------------
Seq Scan on emp (cost=0.00..1.18 rows=1 width=146)
Filter: (empno = 7566::numeric)
(2 rows)
Write a statement in the user session forces index scan for this query.
Answer:
Open a Terminal and login as postgres. Execute following command to connect
to database using PSQL:
[root@localhost ~]# su - postgres
[postgres@localhost ~]$ /opt/PostgreSQL/9.3/bin/psql edbstore
edbstore
Password for user edbstore:
psql.bin (9.3.3)
Type "help" for help.
edbstore=>
edbstore=>
Lab Exercise - 3
• Looking at the statistics you found that some tables are not automatically
maintained by autovacuum. You decided to perform manual maintenance
on some tables. Write a SQL script to perform following maintenance:
• Reclaim obsolete row space from customers table.
• Update statistics for emp and dept tables.
• Mark all the obsolete rows in orders table for reuse
• Execute the newly created maintenance script on edbstore database.
Answer:
Open a Terminal:
[postgres@localhost ~]$ vi edbstore_mnts_script.sql
Lab Exercise - 4
• Composite index named ix_orderlines_orderid on (orderid, orderlineid)
columns of orderlines tables is performing very slow. Write a statement to
reindex this index for better performance.
Answer:
Open a Terminal and login as postgres. Execute following command to connect
to database using PSQL:
[root@localhost ~]# su - postgres
[postgres@localhost ~]$ /opt/PostgreSQL/9.3/bin/psql edbstore
edbstore
Password for user edbstore:
psql.bin (9.3.3)
Type "help" for help.
edbstore=>
edbstore=> REINDEX INDEX ix_orderlines_orderid;
REINDEX
edbstore=>\q
Module 12
Lab Exercise - 1
• You are working with different schemas in a database. After a while you
need to determine all the schemas in your search path. Write a query to
find the list of schemas currently in your search path.
Answer:
Open a Terminal and login as postgres. Execute following command to connect
to database using PSQL:
[root@localhost ~]# su - postgres
[postgres@localhost ~]$ /opt/PostgreSQL/9.3/bin/psql edbstore
edbstore
Password for user edbstore:
psql.bin (9.3.3)
Type "help" for help.
edbstore=> select current_schemas(true);
current_schemas
------------------------------
{pg_catalog,edbstore,public}
(1 row)
edbstore=>
Lab Exercise - 2
• You need to determine the names and definitions of all of the views in
your schema. Create a report that retrieves view information: the view
name and definition text.
• After making a change in postgresql.conf file its time to reload the config
file. Write a statement in psql to reload the config file.
Answer:
Open a Terminal and login as postgres. Execute following command to connect
to database using PSQL:
[root@localhost ~]# su - postgres
[postgres@localhost ~]$ /opt/PostgreSQL/9.3/bin/psql edbstore
edbstore
Password for user edbstore:
psql.bin (9.3.3)
Type "help" for help.
edbstore=>
edbstore=> select * from pg_views where schemaname='edbstore';
edbstore=#
Lab Exercise - 3
Create of report of all the users who are currently connected. The report must
display total session time of all connected users.
You found a user connected to server since long time and decided to gracefully
kill its connection. Write a statement to perform this task.
Answer:
Open a Terminal and login as postgres. Execute following command to connect
to database using PSQL:
[root@localhost ~]# su - postgres
Lab Exercise - 4
Write a query to display name and size of all the databases in your cluster. Size
must be displayed using a meaningful unit.
Answer:
Open a Terminal and login as postgres. Execute following command to connect
to database using PSQL:
[root@localhost ~]# su - postgres
[postgres@localhost ~]$ /opt/PostgreSQL/9.3/bin/psql postgres postgres
Password for user postgres:
psql.bin (9.3.3)
Type "help" for help.
postgres=# select usename,now()-backend_start as "Total Connection
Time", pid from pg_stat_activity;
usename | Total Connection Time | pid
----------+-----------------------+-------
ebuy | 19:41:56.730076 | 13079
postgres | 00:01:52.283003 | 24692
(2 rows)
Module 13
Lab Exercise - 1
Unload emp table from edbstore schema to a csv file, with column headers and a
pipe (|) delimiter.