Top 50 interview questions and answers of Postgresql

Quick intro to PostgreSQL

PostgreSQL is an advanced, enterprise-class, and open-source relational database system. PostgreSQL supports both SQL (relational) and JSON (non-relational) querying.

PostgreSQL is a highly stable database backed by more than 20 years of development by the open-source community.

PostgreSQL is used as a primary database for many web applications as well as mobile and analytics applications.

PostgreSQL’s community pronounces PostgreSQL as /ˈpoʊstɡrɛs ˌkjuː ˈɛl/.

History of PostgreSQL

The PostgreSQL project started in 1986 at Berkeley Computer Science Department, University of California.

The project was originally named POSTGRES, in reference to the older Ingres database which also developed at Berkeley. The goal of the POSTGRES project was to add the minimal features needed to support multiple data types.

In 1996, the POSTGRES project was renamed to PostgreSQL to clearly illustrate its support for SQL. Today, PostgreSQL is commonly abbreviated as Postgres.

Since then, the PostgreSQL Global Development Group, a dedicated community of contributors continues to make the releases of the open-source and free database project.

Originally, PostgreSQL was designed to run on UNIX-like platforms. And then, PostgreSQL was evolved run on various platforms such as Windows, macOS, and Solaris.

Now moving to questions and answers,

1. What is PostgreSQL?

‘Ingres Project’ at UC Berkeley. First Postgres version released in Cross-Platform. Written in C. Used by organisations such as:- Yahoo. MySpace. Skype.

Answer: Postgres or simply known as Postgresql in the SQL world is one of the widely and popularly used for Object-Relational Database Management System that is used mainly in large web applications. It is one of the open-source object-relational database systems which also powerful. It provides additional and substantial power by incorporating four basic concepts in such a way that the user can extend the system without any problem. It extends and uses the SQL language that is combined with various features to safely scale and store the intricate data workloads.

2. List different datatypes of Postgresql?

Answer: There are new, different data-types supported by Postgresql. Following are those data-types:

  • UUID
  • Numeric types
  • Boolean
  • Character types
  • Temporal types
  • Geometric primitives
  • Arbitrary precision numeric
  • XML
  • Arrays etc.
    Users can also create their indexes and get them indexed.

3. What are string constants in PostgreSQL?

Answer: A string constant in PostgreSQL is a sequence of some character that is bounded by single quotes (‘).


‘This is a string Constant’

4. What are the Indices of PostgreSQL?

Answer: Indices of PostgreSQL are inbuilt functions or methods like GIST Indices, hash table and B-tree (Binary tree) which can be used by the user to scan the index in a backward manner. Users can also define their indices of PostgreSQL.

5. What is table partitioning in PostgreSQL?

Answer: Table partitioning in PostgreSQL is the process of splitting a large table into smaller pieces. A partitioned table is a logical structure used to divide a large table into smaller pieces called partitions.

6. What is use of pgadmin in PostgreSQL?

Answer: It is a free open source GUI tool PostgreSQL database administration tool for Windows, Mac OS X, and Linux system. It is used for information retrieval, development, testing, and ongoing maintenance of Databases.

7. How can we change the columns datatype in PostgreSQL?


Use change column type statement with ALTER TABLE command to change a column type in PostgreSQL.


ALTER TABLE table_name
ALTER COLUMN column_name [SET DATA] TYPE new_data_type;

8. Compare ‘PostgreSQL’ with ‘NoSQL’


The expression ‘NoSQL’ encompasses a wide collection of implementations which are part of the non-relational database. This includes tiny embedded databases such as TokyoCabinet, massive bunched data processing platforms such as Hadoop and everything in between. In short, it’s practically impossible to comment on the range comprised by NoSQL as a typical class.

Choosing between the non-relational and relational databases is also quite commonly debated as both have existed alongside each other for over forty years. In fact, users should opt for the features, community support and implementation of the database according to their current application needs. Additionally, use of multiple various databases for sizeable projects is becoming more of a norm than a trend. Moreover, the users of PostgreSQL are no exception.

9. Explain the history of PostgreSQL.


The origin of PostgreSQL dates back to 1986 as part of the POSTGRES project at the University of California at Berkeley and has more than 30 years of active development on the core platform. It runs on all the major operating systems and has been ACID-compliant since 2001. It also has add-on like PostGIS database extender. In MAC OS Postgresql is the default database. Michel Stonebraker is Father of Postgresql who has started the Post Ingres project for supporting Contemporary Database systems.PostgreSQL’s developers pronounce PostgreSQL as It is abbreviated as Postgres because of ubiquitous support for the SQL Standard among most relational databases.PostgreSQL, originally called Postgres, was created at UCB by a computer science professor named Michael Stonebraker, who went on to become the CTO of Informix Corporation.

Stonebraker started Postgres in 1986 as a followup project to its predecessor, Ingres, now owned by Computer Associates. The name Postgres thus plays off of its predecessor (as in “after Ingres”). Ingres, developed from 1977 to 1985, had been an exercise in creating a database system according to classic RDBMS theory. Postgres, developed in 1986-1994, was a project meant to break new ground in database concepts such as exploration of “object-relational” technologies. An enterprise-class database, PostgreSQL boasts sophisticated features such as Multi-Version Concurrency Control (MVCC), point in time recovery, tablespaces, asynchronous replication, nested transactions (savepoints), online/hot backups, a sophisticated query planner/optimizer, and write-ahead logging for fault tolerance.

10. What is the option that can be used in PostgreSQL to make transactions see rows affected in previous parts of the transaction?

Answer: The SQL standard is defined by four levels of transaction isolation basically regarding three phenomena. The three phenomenon must be prevented between concurrent transactions. The unwanted phenomena are:
Phantom read: A transaction that re-executes a query, returning a set of rows that satisfy a search condition and then finds that the set of rows that have been satisfying the condition has changed due to another recently-committed transaction.
Non-repeatable read: A transaction that re-reads the data that it has previously read and then finds that data has already been modified by another transaction (that committed since the initial read).
Dirty read : A transaction when reads data that is written by a concurrent uncommitted transaction is the dirty read.

11. Provide a brief explanation of the functions in Postgresql.

Answer: Anywhere, functions are an important part because they help in executing the code on the server. Some of the languages to program functions are PL/pgSQL, a native language of PostgreSQL, and other scripting languages like Perl, Python, PHP, etc. statistical language named PL/R can also be used to increase the efficiency of the functions.

12. Do provide an explanation for pgadmin? (100% asked Postgresql Interview Questions)

Answer: Pgadmin is a feature that is known to form a graphical front-end administration tool. This feature is available under free software released under Artistic License. Pgadmin iii is the new database administration tool released under artistic license.

13. Provide an explanation About Write Ahead Logging?

Answer: WAL or write-ahead logging is a standard method to ensure data integrity. It is a protocol or the correct rule to write both actions and changes into a transaction log. This feature is known to increase the reliability of the database by logging changes before any changes or updating to the database. This provides the log of the database in case of a database crash. This helps to start the work from the point it was discontinued.

14. What is difference between clustered index and non clustered index?

Answer: Difference between clustered index and non clustered index

  • Cluster index is an index type that is used to sort table data rows on the basis of their key values. In RDBMS primary key allows us to create a clustered index based on that specific column.
  • A non-clustered index (or regular b-tree index) is an index where the order of the rows does not match the physical order of the actual data. It is instead ordered by the columns that make up the index.

15. What Is A Ctid?

Answer: CTIDs is a field, which exists in every PostgreSQL table and is known to identify specific physical rows according to their block and offset positions within a particular table. They are used by index entries to point to physical rows. It is unique for each record in the table and easily denotes the location of a tuple. A logical row’s CTID changes when it is updated, so the CTID cannot be used as a long-term row identifier. However, it is sometimes useful to identify a row within a transaction when no competing update is expected.

16. Which are different types of database administration tools used in Postgresql?

Answer: There are the number of data administration tools, and they are

  • Phppgadmin
  • Psql
  • Pgadmin
  • Out of these, phppgadmin is the most popular one. Most of these tools are front-end administration tools and web-based interfaces.

17. Put some light on Multi-Version concurrency control?

Answer: MVCC or better known as Multi-version concurrency control is used to avoid unwanted locking of the database. The time lag for the user is removed so that one can easily log into his database. All the transactions are well- kept as a record. The time lag occurs when someone else is on the content.

18. What is the command enable-debug in PostgreSQL?

Answer: The command enable-debug is used to enable the compilation of all the applications and libraries. The execution of this procedure usually impedes the system, but it also amplifies the binary file size. Debugging symbols which are present generally assist the developers for spotting the bugs and other problems which may arise associated with their script.

19. What will be the new characteristics of Postgre 9.1?

Answer: During the process of updating the project, one can never be certain what features will go in and which ones won’t make the cut. The project has precise and stringent standards for quality, and some patches may or may not match them before the set deadline. Currently, the 9.1 version is working on some important features which include JSON support, synchronous replication, nearest-neighbor geographic searches, collations at the column level, SQL/MED external data connections, security labels as well as index-only access. However, this list has a high chance of changing completely by the time Postgre 9.1 is released.

20. How are the stats updated in Postgresql?


It is not that hard as it seems. To get your statistics updated in PostgreSQL a special function called explicit ‘vacuum’ call is made. The method to do is to create a Vacuum where the option of Analyze is used to update statistics in Postgresql

is the syntax.

21. What is Cube Root Operator (||/) in PostgreSQL?


PostgreSQL Cube Root Operator (||/) is used to get the cube root of a number.


SELECT ||/40 AS “Cube Root of 40”;

22. How to start database server in PostgreSQL?

Answer: Before you can have access to the database, you must be able to start the database server. The server program of the database is called Postgres. The Postgres program must know where to find the data it is supposed to use. This is done with the -D option. Thus, the simplest way to start the server is:

  1. /usr/local/etc/rc.d/ start
  2. /usr/local/etc/rc.d/PostgreSQL start

23. What are tokens in PostgreSQL?

Answer: Tokens in PostgreSQL are the building blocks of any source code. They are known to comprise many of the special character symbols. These can be regarded as constants, quoted identifiers, other identifiers, and keywords. Tokens which are keywords consist of pre-defined SQL commands and meanings. Identifiers are used to represent variable names like columns, tables, etc.

24. What is multi-version control in PostgreSQL?

Answer: Multi-version concurrency control or MVCC in PostgreSQL is used to avoid unnecessary locking of the database. This removes the time lag for the user to log into his database. This feature or time lag occurs when someone else is accessing the content. All the transactions are kept as a record.

25. List different advantages of Postgresql?

Answer: Following are some of the advantages of PostgreSQL :

  • Stable
  • Reliable
  • Extensible
  • Easy to learn
  • Open source
  • Designed for High Volume Environments
  • Cross Platform
  • Better Support
  • Flexible

26. List some of the features of Postgresql ?

Answer: Following are some of the major features of Postgresql :

  1. Object-relational database
  2. Supports major Operating systems
  3. Support Extensibility for SQL and Complex SQL queries
  4. Nested transactions
  5. Flexible API and Database validation
  6. Multi-version concurrency control (MVCC) and Procedural languages
  7. WAL and Client server
  8. Table inheritance & Asynchronous replication

27. State Some Of The Advanced Features Of Postgresql?

Answer: These are the following features which are present in PostgreSQL they are

1) Object relational database
2) Extensibility and support for SQL
3) Database validation and flexible API
4) Procedural languages and MVCC
5) Client server and WAL.

28. Explain About Write Ahead Logging?

Answer: This feature increases the reliability of the database by logging changes before any changes or updations to the data base. This provides log of database incase of a database crash. This helps to start the work from the point it was discontinued.

29. How To Start The Database Server?


  1. /usr/local/etc/rc.d/ start
  2. /usr/local/etc/rc.d/postgresql start

30. What Are The Languages Which Postgresql Supports?

Answer: Some of the languages which PostgreSQL supports are as follows:
It supports a language of its own known as PL/pgSQL and it supports internal procedural languages. Pl/pgSQL can be compared to oracle, PL/SQL, etc. Languages such as Perl, Python, TCL can be used as embedded languages.

31. Explain About The Command Enable Debug?

Answer: This command is used for enabling compilation of all libraries and applications. This process generally slows down the system and it also increases the binary file size. Debugging symbols are present which can assist developers in noticing bugs and problems associated with their script.

32. Explain About Indices Of Postgresql?

Answer: There are built in functions such as B-tree, hash table, and GIST indices can be used or users can define their own indices. PostgreSQL can scan the index backwards. Expression index could be created with the result of an expression. Partial index created with addition of WHERE clause.

33. What Are The Different Data Types Supported By Postgresql?


There are different data types which are supported they are:

1) Arbitrary precision numeric’s
2) Geometric primitives
3) Arrays
4) XML etc
Users can create their own indexes and make them indexed.

34. Explain About Pgadmin?

Answer: Pgadmin forms a graphical front end administration tool. This feature is available under free software released under Artistic License. Pgadmin iii is the new database administration tool released under artistic license.

35. What Are The Various Enhancements To The Straight Relational Data Model By Postgresql?

Answer: There are various enhancements provided to the straight relational data model by postgre SQl they are support for arrays which includes multiple values, inheritance, functions and extensibility. Jargon differs because of its object oriented nature where tables are called as classes.

36. Explain About String Constants?

Answer: String constant contains a sequence of characters bound by single quotes. This feature is used during insertion of a character or passing character to database objects. PostgreSQL allows the usage of single quotes but embedded by a C style backslash. This feature is important in parsing data.

37. What Is A Sequence?

Answer: A sequence is a special kind of database object designed for generating unique numeric identifiers. It is typically used to generate artificial primary keys.
Sequences are similar, but not identical, to the AUTO_INCREMENT concept in MySQL.

38. How Do I Tell What Postgresql Version I Am Running?

Answer: Run this query: SELECT version();

39. How Do I Perform An Outer Join?

Answer: PostgreSQL supports outer joins using the SQL standard syntax. Here are two examples:

SELECT * FROM t1 LEFT OUTER JOIN t2 ON (t1.col = t2.col);

40. Is Possible To Create A Shared-storage Postgresql Server Cluster?

Answer: PostgreSQL does not support clustering using shared storage on a SAN, SCSI backplane, iSCSI volume, or other shared media. Such “RAC-style” clustering isn’t supported. Only replication-based clustering is currently supported.

41. How To Pronounce Postgresql?

Answer: post-GRES-que-ell, per this audio file. Many people, however, just say “post-GRES”.

42. Does Postgresql Run On The Cloud?

Answer: Yes. Like other open source databases, PostgreSQL is easy to run in virtual containers and is highly portable. Several companies have support for PostgreSQL in cloud hosting environments, including Heroku, GoGrid and Joyent

43. Explain About Concurrency With The Help Of Mvcc?.

Answer: Multi version concurrency control is used to manage concurrency. This feature is very useful because changes made in the database will not be visible to other users until the transaction is completed. This removes the need for read locks. ACID principles are given a further boost by this feature and can be implemented in general.

44. How Does Postgresql Compare To Mysql?

Answer: This is a topic that can start several hours of discussion. As a quick summary, MySQL is the “easy-to-use, web developer” database, and PostgreSQL is the “feature-rich, standards-compliant” database. PostgreSQL is liberally licensed and owned by its community; MySQL is GPL-licensed and owned by Oracle. Beyond that, each database user should make his own evaluation; open source software makes doing comparisons very easy.

45. How do you delete the database in PostgreSQL?


We can delete the database by using any one of the below options:

  • Using DROP DATABASE, an SQL command
  • Using dropdb a command-line executable

46. What are the different operators in PostgreSQL?

Answer: The PostgreSQL operators include – Arithmetic operators, Comparison operators, Logical operators, and Bitwise operators.

47. What indexes are used?

Answer: Indexes are used by the search engine to speed up data retrieval.

48.What do you need to do to update statistics in PostgreSQL?

Answer: To update statistics in PostgreSQL, we need to use a special function called a vacuum.

49. What are the different properties of a transaction in PostgreSQL? Which acronym is used to refer to them?

Answer: The properties of a transaction in PostgreSQL include Atomicity, Consistency, Isolation, and Durability. These are referred to by the acronym, namely ACID.

50. How is security ensured in PostgreSQL?

Answer: PostgreSQL uses SSL connections to encrypt client or server communications so that security will be ensured

Rajesh Kumar
Follow me
Notify of
Inline Feedbacks
View all comments
Would love your thoughts, please comment.x