PostgreSQL Quiz - MCQ - Multiple Choice Questions

Welcome to the PostgreSQL Quiz for beginners! Whether you're testing your knowledge or looking to learn something new, this quiz has you covered. We will be covering the fundamental concepts of PostgreSQL through 40+ multiple-choice questions. Let's dive in!

1. What is PostgreSQL?

A. A NoSQL database
B. A relational database management system (RDBMS)
C. A programming language
D. A web server

2. Which of the following is a key feature of PostgreSQL?

A. Support for JSON
B. Exclusively uses the MyISAM storage engine
C. Proprietary software
D. Limited to small datasets

3. Which command-line utility is used for interactive PostgreSQL operations?

A. pgadmin
B. psql
C. pgsql
D. adminsql

4. Which SQL command is used to create a new PostgreSQL database?

A. NEW DATABASE
B. ADD DATABASE
C. CREATE DATABASE
D. DATABASE CREATE

5. How do you add a comment in SQL in PostgreSQL?

A. /* Comment Here */
B. // Comment Here
C. -- Comment Here
D. # Comment Here

6. Which data type in PostgreSQL can be used to store binary data?

A. CHAR
B. BINARY
C. BYTEA
D. DATA_BYTE

7. Which command in PostgreSQL is used to list all the available databases?

A. SHOW DATABASES;
B. \ld
C. \l
D. DISPLAY DATABASES;

8. Which keyword is used in PostgreSQL to define a primary key constraint?

A. PRIMARY
B. KEY
C. UNIQUE
D. PRIMARY KEY

9. Which of the following PostgreSQL functions can be used to obtain the current date and time?

A. GET_TIMESTAMP()
B. CURRENT_TIMESTAMP
C. NOW_DATE_TIME()
D. FETCH_DATETIME()

10. What is the maximum length of a table name in PostgreSQL?

A. 32 characters
B. 64 characters
C. 128 characters
D. 256 characters

11. Which PostgreSQL function returns the number of characters in a string?

A. STRLEN()
B. LENGTH()
C. CHAR_COUNT()
D. NUMCHAR()

12. What does the SERIAL keyword in PostgreSQL do?

A. Creates a series of numbers
B. Creates an auto-increment integer column
C. Serializes a table for export
D. Links tables in a series

13. In which language is PostgreSQL written?

A. Python
B. Java
C. C
D. Ruby

14. Which of the following is NOT a valid backup option for PostgreSQL?

A. pg_dump
B. pg_restore
C. pg_backup
D. pg_basebackup

15. Which command can be used to see the query plan for a statement without executing it?

A. EXPLAIN
B. DESCRIBE
C. QUERY PLAN
D. INSPECT

16. Which PostgreSQL feature allows for partitioning tables?

A. Table Slicing
B. Table Mapping
C. Table Segmentation
D. Table Inheritance

17. How do you retrieve the version of the PostgreSQL server you're connected to?

A. SHOW VERSION();
B. SELECT version();
C. RETRIEVE VERSION;
D. SELECT @version;

18. Which command-line utility is used for administrative tasks like creating, deleting, and maintaining PostgreSQL databases?

A. pgadmin
B. pgsql
C. psql
D. createdb and dropdb

19. Which datatype is used in PostgreSQL to store IPv4 and IPv6 addresses?

A. IP
B. NET_ADDR
C. INET
D. NETWORK

20. Which command can be used to list all the tables in the current PostgreSQL database?

A. \tables
B. \l
C. \dt
D. LIST TABLES;

21. Which of the following is NOT a locking mechanism in PostgreSQL?

A. Advisory Locks
B. Tuple Locks
C. Transaction Locks
D. Segment Locks

22. PostgreSQL is often referred to as an ORDBMS. What does the "OR" stand for?

A. Operational Relational
B. Object-Relational
C. Organized Record
D. Open-Resource

23. How would you retrieve unique values from a column named "names" in a table called "users"?

A. SELECT DISTINCT(names) FROM users;
B. UNIQUE SELECT names FROM users;
C. SELECT names UNIQUE FROM users;
D. GET DISTINCT names FROM users;

24. Which function would you use to obtain the current user name in PostgreSQL?

A. GET_USER();
B. CURRENT_USER();
C. USER_NAME();
D. CURRENT_USER;

25. Which command will allow you to switch to a different database named 'testdb' in the psql interface?

A. USE testdb;
B. \c testdb;
C. SWITCH testdb;
D. SELECT DATABASE testdb;

26. What is the primary role of the WAL in PostgreSQL?

A. Web Access Layer
B. Write Ahead Logging
C. Write After Load
D. Workload Allocation Logic

27. Which of the following data types would be best for storing monetary values in PostgreSQL?

A. FLOAT
B. INTEGER
C. MONEY
D. DECIMAL

28. What is the purpose of the VACUUM command in PostgreSQL?

A. To clean and optimize the database
B. To backup the database
C. To restore the database
D. To migrate data

29. Which of these is a PostgreSQL tool for creating a physical backup?

A. pg_dump
B. pg_backup
C. pg_basebackup
D. pg_clone

30. How do you concatenate two columns in PostgreSQL?

A. USING
B. JOIN
C. +
D. ||

31. Which of these commands is used to remove a table from PostgreSQL?

A. DELETE TABLE
B. DROP TABLE
C. REMOVE TABLE
D. DISCARD TABLE

32. What does the CASCADE option do when used with the DROP TABLE command?

A. Drops the table and all associated indexes
B. Drops the table and any dependent objects
C. Recreates the table after dropping
D. Ignores any dependencies and drops the table

33. What is the default port on which PostgreSQL listens?

A. 3306
B. 8080
C. 5432
D. 80

34. Which command in psql will list all the databases?

A. \list
B. \databases
C. \showdb
D. \db

35. How would you describe the structure of a table named "employees" using psql?

A. \d employees
B. DESCRIBE employees;
C. \tableinfo employees
D. \struct employees

36. If you want to see the list of users and their roles in psql, which command would you use?

A. \users
B. \roles
C. \du
D. \listusers

37. Which psql command would you use to turn on the timing of commands?

A. \timeon
B. \timing
C. \showtime
D. \settime

38. How would you quit out of the psql interface?

A. \exit
B. QUIT;
C. \q
D. LEAVE;

39. Which command is used to display the history of executed SQL commands in psql?

A. \history
B. \h
C. \s
D. \log

40. What does the psql command \e do?

A. Exits the psql shell
B. Opens the last SQL command in an editor
C. Executes the SQL command
D. Echoes the SQL command

Comments

Spring Boot 3 Paid Course Published for Free
on my Java Guides YouTube Channel

Subscribe to my YouTube Channel (165K+ subscribers):
Java Guides Channel

Top 10 My Udemy Courses with Huge Discount:
Udemy Courses - Ramesh Fadatare