PostgreSQL MCQs

PostgreSQL MCQs

These PostgreSQL multiple-choice questions and their answers will help you strengthen your grip on the subject of PostgreSQL. You can prepare for an upcoming exam or job interview with these PostgreSQL MCQs.
So scroll down and start answering.

1: PostgreSQL can be used from just about any major programming language, including C, C++, Perl, Python, Java, Tcl, and PHP.

A.   True

B.   FALSE

2: The value NULL, in database terminology, means?

A.   The value is not relevant for this particular row.

B.   The value is undetermined

C.   The value is undetermined at this time

D.   All of these

3: True or false: With table inheritance, not null and check constraints are inherited.

A.   False

B.   True

4: What do you call the application that makes requests of the PostgreSQL server?

A.   Workstation

B.   Thin Client

C.   Interface

D.   Client

5: What is the wrapper around the SQL command CREATE DATABASE?

A.   newdb

B.   add_DB

C.   NEW_DB

D.   createdb

6: When retrieving data in a particular table, we use the_____________ statement.

A.   SELECT FROM

B.   \dt

C.   \i<filename>

D.   ORDER BY

7: PostgreSQL is:

A.   An open-source ORDBMS developed at UC Berkley, which supports many modern features.

B.   Enterprise-class proprietary software developed at Bell Labs, with a basic set of features.

C.   A NoSQL solution.

D.   An open-source SMTP server.

8: PostgreSQL is

A.   an XML database management system.

B.   a network-type database management system.

C.   a hierarchical database management system.

D.   a relational database management system.

9: PostgreSQL has many modern features including:

A.   SQL Sub-selects

B.   All of the above

C.   Views

D.   Complex SQL queries

10: PostgreSQL can be installed?

A.   from the source code

B.   from Linux binaries

C.   on a Windows computer via the PostgreSQL installer

D.   All of these

11: PostgreSQL runs on:

A.   Windows only

B.   all major operating systems, including Linux, UNIX (AIX, BSD, HP-UX, SGI IRIX, Mac OS X, Solaris, Tru64), and Windows.

C.   on all UNIX versions except Solaris.

D.   Linux and Windows only.

12: With PostgreSQL, you can access data by

A.   Use function calls (APIs) to prepare and execute SQL statements, scan result sets, and perform updates from a large variety of different programming languages.

B.   Embed SQL directly into your application

C.   Use a command-line application to execute SQL statements

D.   All of these

13: Triggers can be configured to execute when which of the following operations are performed:

A.   All of the above

B.   DELETE statements

C.   INSERT statements

D.   UPDATE statements

14: We add data to PostgreSQL by using which statement?

A.   UPDATE

B.   ADD

C.   SELECT

D.   INSERT

15: The heart of SQL is the __________ statement.

A.   VALUES

B.   INSERT INTO

C.   SELECT

D.   GROUP BY

16: The most common method to get data into a table is to use what command?

A.   Write

B.   Send

C.   Execute

D.   Insert

17: In PostgreSQL, a named collection of tables is called what?

A.   Schema

B.   View

C.   Diagram

D.   Trigger

18: What command tells PostgreSQL that all of the changes you made to a database should become permanent?

A.   Commit

B.   Send

C.   Apply

D.   Execute

19: The SQL condition for pattern matching is?

A.   IN

B.   DISTINCT

C.   LIKE

D.   BETWEEN

20: ____________ allow us to define formally in the database how different tables relate to each other.

A.   table management

B.   Views

C.   temporary tables

D.   Foreign Key Constraints

21: Which of the following best describes a role:

A.   The purpose of a particular database.

B.   A cluster's purpose.

C.   A server's purpose within a cluster.

D.   A template for authorization to various database objects.

22: The basic psql command to list tables is?

A.   \do

B.   \h

C.   \dT

D.   \dt

23: True or False? VACUUM FULL shrinks indexes, optimizing database performance.

A.   True - This was addressed in version 9.0

B.   False - This was addressed in version 9.0

24: WAL stands for:

A.   Write Anywhere List

B.   Write Anywhere Logging

C.   Write Ahead Log

D.   Write Ahead List

25: Deadlocks occur when:

A.   Two users try to access the same table at the same time.

B.   Two users are connected to the same database at the same time.

C.   Data is being written to the same cell by separate processes at the same time.

D.   Two transactions hold exclusive locks on resources they both need.

26: True or False? When using a SELECT statement on a table, or group of tables, those resources are locked exclusively.

A.   False

B.   True

27: Tablespaces:

A.   Allow an administrator to designate specific locations in a file system where database objects can be stored.

B.   Are a fancy name for table.

C.   Are the width, or number of columns, of a particular table.

D.   Are the amount of disk space a table is using.

28: If you don’t specify ASC or DESC, PostgreSQL will assume you want to see results:

A.   in ascending order

B.   in a random order

C.   grouped together by field type

D.   in descending order

29: True or False: A tablespace is the place where database objects are stored on disk.

A.   True

B.   False

30: When you want to use a join between columns that are in the same table, you use what type of join?

A.   right outer

B.   left outer

C.   union

D.   self

31: True or False? Within a table, a single column may be encrypted.

A.   False

B.   True

32: True or False? ALTER TABLE may be issued while a VACUUM process is running.

A.   False

B.   True

33: The core PostgreSQL source code includes what interfaces?

A.   VB and VB.NET interfaces

B.   The C and embedded C interfaces

C.   Ruby and PHP interfaces

D.   C++ and Java interfaces

34: A VACUUM operation is used:

A.   All of these

B.   To recover or reuse disk space occupied by updated or deleted rows.

C.   To update data statistics used by the PostgreSQL query planner.

D.   To protect against loss of very old data due to transaction ID wraparound.

35: True or False? PostgreSQL is so lightweight that performance and reliability are not affected by hardware.

A.   False

B.   True

36: Unless you specify NOT NULL, PostgreSQL will assume that a column is:

A.   Optional

B.   Text

C.   Required

D.   Integers

37: To describe a table in PostgreSQL which of the following is correct:

A.   psql> describe table_name

B.   psql> \D table_name

C.   psql> DESCRIBE table_name

D.   psql> \d table_name

38: Query trees can be viewed in the server logs as long as which of the following configuration parameters are enabled?

A.   debug_print_parse

B.   All of these

C.   debug_print_rewritten

D.   debug_print_plan

39: A meta-command always begins with what?

A.   Backslash character (\)

B.   Dollar sign ($)

C.   Question mark (?)

D.   Forwardslash character (/)

40: To create a database in PostgreSQL, you must have the special CREATEDB privilege or

A.   the special CREATETBL privilege

B.   have a script do it.

C.   be a superuser.

D.   be an admin

41: What does the following statement do? CREATE INDEX lower_title_idx ON books ((lower(title)));

A.   Nothing, it's invalid SQL

B.   Creates a non-write-locking index

C.   Modifies an index in place to be lowercase

D.   Creates a new index with a special operator class 'lower' for case insensitive comparisons.

E.   Creates an index for efficient case-insensitive searches on the titles column within the books table

42: What command allows you to edit PostgreSQL queries in your favorite editor ?

A.   \ed

B.   edit sql #go

C.   \edit

D.   \e

43: To prevent transaction wraparound, a VACUUM operation should be run on every table no less than once every:

A.   4 billion transactions

B.   3 billion transactions

C.   2 billion transactions

D.   5 billion transactions

44: Asynchronous Commits:

A.   May cause recent transactions to be lost

B.   None of these

C.   All of these

D.   Allow transactions to complete more quickly

45: The rule system:

A.   Takes the output of the parser, one query tree, and the user-defined rewrite rules, which are also query trees with some extra information, and creates zero or more query trees as result.

B.   Operates between the parser and the planner.

C.   None of these

D.   All of these

46: True or False? Only the administrator can make use of tablespaces.

A.   False

B.   True

47: What command turns on timing?

A.   \start time

B.   \timing

C.   \on timing

D.   \time start

48: When looking at 'ps' output on a unix system, you see the following: postgres 1016 0.1 2.4 6532 3080 pts/1 SN 13:19 0:00 postgres: tgl regression [local] idle in transaction What does "idle in transaction" mean?

A.   A client is connected, and the server is awaiting input.

B.   The server is idle, awaiting a client connection.

C.   A transaction is possibly hung.

D.   A user issued an IDLE statement to the database.

49: Advisory locks are allocated out of a shared memory pool whose size is defined by the configuration variables....

A.   max_connections

B.   None of these

C.   max_locks_per_transaction

D.   All of these

50: This is used to determine how text is stored and sorted within PostgreSQL?

A.   Collations

B.   Index

C.   Data Types

D.   Database

51: True or False? Dynamic Tracing is enabled by default at compile time.

A.   True

B.   False

52: Which statement is true about PostgreSQL data types?

A.   n'in CHARACTER(n) represents the number of bytes.

B.   A large object data type can be used to store data of unlimited size.

C.   There is a non-standard PostgreSQL data type, called Geometric data type, which handles 2-dimensional data.

D.   Only the INTEGER type can be declared as an array.

53: True or False? PostgreSQL supports Index Only Scans.

A.   False

B.   True

54: What does MCV stand for?

A.   Massive Checkpoint Vault

B.   Many Common Variables

C.   Most Common Variables

D.   Most Common Values

55: To restore a PostgreSQL backup created with pg_dump, the following may be used:

A.   $ psql -F database_dump.psql database_name

B.   $ psql -f database_dump.psql database_name

C.   $ psql -R database_dump.psql database_name

D.   $ psql -r database_dump.psql database_name

56: In order to echo all input from script, you use the ________ psql command.

A.   -l

B.   -A

C.   -E

D.   -a

57: By default, in what subdirectory of the database data directory are WAL logs contained?

A.   pg_log

B.   pg-xlog

C.   pg_xlog

D.   pg-log

58: What is "index bloat"?

A.   Indexing too many tables, resulting in inefficient database performance.

B.   No-longer-needed keys in an index aren't reclaimed, therefore increasing space required to store an index, as well as time it takes to scan.

C.   Indexing inefficiently, like choosing to index timestamps in a table.

D.   Index filling up with keys.

59: Which is NOT true of array indexes?

A.   Partial functional indexes of arrays are supported on Btree, GiST, and GIN indexes.

B.   GiST indexes can be used to select arrays for specific values.

C.   GIN indexes can search for arrays containing specific elements.

D.   By default PostgreSQL indexes arrays so that inner elements can be searched.

E.   BTree indexes can search for array elements as long as the match begins with the beginning of the array.

60: Bob works for StegaCorp. His workstation's IP address is 10.5.34.8. He needs access to a database called "partners" directly from his workstation. Which of the following is the correct entry in pg_hba.conf?

A.   host partners bob 10.5.34.8/32 krb5

B.   host partners bob 10.5.34.8 kerb5

C.   host partners bob 10.5.34.8/24 krb5

D.   host partners bob 10.5.34.8/32 kerb5

61: What are the join strategies available to the postgreSQL planner when a SELECT query contains two or more relations?

A.   INNER JOIN, OUTER JOIN

B.   MERGE, INNER JOIN, OUTER JOIN

C.   MERGE, JOIN

D.   Nested Loop Join, Merge Join, Hash Join

62: To copy a database from server1 to server2, you might use which of the following:

A.   pg_mv -h server1 database | pgsql -h server2 database

B.   pg_dump -h server1 database > pgsql -h server2 database

C.   pg_dump -h server1 database | psql -h server2 database

D.   pg_copy -h server1 database | psql -h server2 database

63: True or False? To increase server performance, automated CHECKPOINT operations should be setup in cron or Task Scheduler.

A.   False

B.   True

64: Which of the following is not a valid integer array?

A.   '{1,3,4,5,6,7}'

B.   '{{1,2},{1,3},{1,4},{2,5}}'

C.   '{}'

D.   '{1,3,4,5,{6,7}}'

E.   '{{1,2,3,4,5,6}}'

65: What is the difference between DO 'some code...' and EXECUTE 'some code...' statements?

A.   DO prepares a statement and EXECUTE executes it

B.   No difference - they both need a preparation for execution

C.   No difference - they both can execute a code without preparation

D.   EXECUTE statement executes only prepared code, and DO can execute without PREPARE statement

E.   DO lets you execute some plPgSql code without saving it to database and EXECUTE lets you execute DDL or DML only

66: Locks are recorded in:

A.   pg_lock system table

B.   pg_locks system view

C.   pg_lock system logs

D.   pg_locks system logs

67: True or False? When restoring a database backed up with pg_dump, it's generally a good idea to enable WAL.

A.   True

B.   False

68: True or false? Hash indexes are not crash-safe

A.   False

B.   True

69: True or false: When a table is created which uses a table name as a column type, not null constraints on the column type's table definition are honored by the including table.

A.   True

B.   False

70: The syntax to view the indexes of an existing postgreSQL table is:

A.   # index database_name.table_name

B.   # \i table_name

C.   # \d table_name

D.   # index table_name

71: Which statement is not true about a PostgreSQL domain?

A.   A domain can be used as a column type when defining a table.

B.   When defining a domain, you can add a default value and constraints to the original data.

C.   A domain is created by 'CREATE DOMAIN'.

D.   Domain is a namespace existing between databases and objects such as tables.

72: The extension used for data encryption/decryption within PostgreSQL is:

A.   pgcrypto

B.   crypto

C.   pgcrypt

D.   pgencrypt

73: What is a TOAST file?

A.   A file containining transactions which were unsuccessfully completed due to errors.

B.   A list of clients not allowed to connect to the database.

C.   A file containing values too wide to fit comfortably in the main table

D.   A file storing data that was unable to be written to the database, and will be expunged once the server shuts down.

74: To create a database that supports UTF-8, the following command can be used:

A.   createdb -E UTF-8 -O user database_name

B.   createdb -C UTF8 database_name

C.   createdb -C UTF8 -O user database_name

D.   createdb -E UTF8 -O user database_name

75: True or False: PostgreSQL allows you to implement table inheritance. This should be defined with the special keyword INHERITIS in the table design.

A.   False

B.   True

76: Which of the following is NOT a feature of user defined functions?

A.   Functions marked IMMUTABLE can have their output indexed

B.   They can be written in various different languages

C.   They can perform most database management tasks

D.   They can return multiple result sets via refcursors

E.   They can initiate subtransactions

77: WAL segment size is determined:

A.   It is statically set within the source code.

B.   By the administrator at runtime, or through the startup script.

C.   By the wal_segment_size configuration parameter in postgresql.conf

D.   By the configure script at compile time

A.   hierarchical

B.   structured

C.   relational

D.   network

79: When identifying rows uniquely, we use__________keys.

A.   command

B.   standard

C.   surrogate

D.   unique

80: True or false: With table inheritance child tables inherit primary and foreign key definitions from their parents

A.   False

B.   True

81: True or False? To enable continuous archiving, all you have to do is set archive_mode to

A.   True

B.   False

82: Can deferrable constraints be deferred by a trigger?


A.   Yes

B.   No 

83: How do you create a table with a field of the int array type?


A.   create table foo (bar int array);

B.   create table foo (bar integer[]);

C.   create table foo (bar array int);

D.   create table foo (bar[] int);

E.   None of the above 

84: PostgreSQL triggers can be written in C directly.


A.   True

B.   False 

85: Which index types are supported by PostgreSQL?


A.   A-tree

B.   B-tree

C.   GiST

D.   Hash

E.   GIN

F.   None of the above 

86: What command will correctly restore a backup made with the following command?
pg_dump -Fc dbname > filename


A.   psql -f filename dbname

B.   psql -Fc filename dbname

C.   pg_restore filename dbname

D.   pg_restore -d dbname filename

E.   None of the above 

87: What is the effect of turning fsync off in postgresql.conf?


A.   File synchronization will be deactivated

B.   fsync is not a valid configuration option

C.   PostgreSQL will not enforce write ahead log flush

D.   It will turn off fast synchronization

E.   None of the above 

88: Which kind of index can be declared unique?


A.   Hash

B.   A-tree

C.   B-tree

D.   GIN

E.   GiST

89: Which authentication methods are supported by PostgreSQL?


A.   Trust

B.   PAM

C.   LDAP

D.   Radius

E.   Password

90: If max_connections is 10 and 10 connections are currently active, how can you be sure the superuser will be available to connect?


A.   You cannot

B.   Leave a superuser connected all the time

C.   Set superuser_reserved_connections in postgresql.conf

D.   Kill postmaster and connect to it

E.   None of the above 

91: Which function should be used to highlight the results?


A.   ts_highlight

B.   ts_tag

C.   ts_headline

D.   ts_select

E.   None of the above 

92: Consider the following query:

Create table foo (bar varchar);

What will be the size limit of the bar?


A.   256

B.   1024

C.   1

D.   No limit (It will be equivalent to the text)

E.   None of the above 

93: An ISO-8601 time may be entered into a table using the numeric format 012411 instead of 01:24:11.


A.   True

B.   False 

94: The following statement will retrieve the second element of the array column products in table store_products.

SELECT products[1] FROM store_products;


A.   True

B.   False 

95: What is the well known port number for the postgresql database service?


A.   5000

B.   541

C.   5432

D.   63

E.   None of the above 

96: What kind of triggers are offered by PostgreSQL?


A.   Per-row triggers

B.   Per-table triggers

C.   Per-database triggers

D.   Per-statement triggers 

97: When using LIKE to compare strings, what is the wildcard operator (operator which matches zero or more characters)?


A.   *

B.   $

C.   %

D.   &

E.   None of the above 

98: What can be stored in a column of type decimal(4,3)?


A.   4 numeric values with up to 3 digits to the right of the decimal point.

B.   A numeric value with up to 7 digits in total, 3 of which can be to the right of the decimal point.

C.   A numeric value with up to 4 digits in total, 3 of which can be to the right of the decimal point.

D.   A numeric value with at least 4 digits, 3 of which must be to the right of the decimal point. 

99: What is the default ordering when ORDER BY is not specified?


A.   By ID

B.   By insertion date

C.   By name

D.   The ordering is unknown if not specified

E.   None of the above 

100: How do you select a single random row from a table?


A.   SELECT random() * FROM tab LIMIT 1;

B.   SELECT * FROM tab ORDER BY random() LIMIT 1;

C.   SELECT * FROM tab RANDOM LIMIT 1 ;

D.   SELECT RANDOM 1 from tab;

E.   None of the above