{"id":7549,"date":"2023-06-12T12:02:29","date_gmt":"2023-06-12T06:32:29","guid":{"rendered":"https:\/\/www.interviewbit.com\/blog\/?p=7549"},"modified":"2023-06-12T12:02:31","modified_gmt":"2023-06-12T06:32:31","slug":"postgresql-commands","status":"publish","type":"post","link":"https:\/\/www.interviewbit.com\/blog\/postgresql-commands\/","title":{"rendered":"Top PostgreSQL Commands You Must Know"},"content":{"rendered":"\n<div class=\"gutentoc tocactive ullist\"><div class=\"gutentoc-toc-wrap\"><div class=\"gutentoc-toc-title-wrap\"><div class=\"gutentoc-toc-title\">Table Of Contents<\/div><div id=\"open\" class=\"text_open\">show<\/div><\/div><div id=\"toclist\"><div class=\"gutentoc-toc__list-wrap\"><ul class=\"gutentoc-toc__list\"><li><a href=\"#postgresql-commands-list\">PostgreSQL Commands List<\/a><\/li><ul class=\"gutentoc-toc__list\"><li><a href=\"#1-connect-to-postgresql-database\">1. Connect to PostgreSQL Database<\/a><\/li><li><a href=\"#2-change-the-database-connection-to-a-new-one\">2. Change the database connection to a new one<\/a><\/li><li><a href=\"#3-list-available-database\">3. List available database<\/a><\/li><li><a href=\"#4-list-available-table\">4. List available table<\/a><\/li><li><a href=\"#5-describe-table\">5. Describe table<\/a><\/li><li><a href=\"#6-list-available-schema\">6. List available schema<\/a><\/li><li><a href=\"#7-list-available-function\">7. List available function<\/a><\/li><li><a href=\"#8-list-all-views\">8. List all views<\/a><\/li><li><a href=\"#9-list-users-and-roles\">9. List users and roles<\/a><\/li><li><a href=\"#10-execute-the-previous-command\">10. Execute the previous command<\/a><\/li><li><a href=\"#11-command-history\">11. Command History<\/a><\/li><li><a href=\"#12-execute-psql-commands\">12. Execute psql commands<\/a><\/li><li><a href=\"#13-get-help-on-psql-commands\">13. Get help on psql commands<\/a><\/li><li><a href=\"#14-turn-on-query-execution-time\">14. Turn on query execution time<\/a><\/li><li><a href=\"#15-edit-command-in-your-editor\">15. Edit command in your editor<\/a><\/li><li><a href=\"#16-switch-output-options\">16. Switch output options<\/a><\/li><li><a href=\"#17-quit-psql\">17. Quit psql<\/a><\/li><\/ul><li><a href=\"#faqs\">FAQs<\/a><\/li><ul class=\"gutentoc-toc__list\"><li><a href=\"#q1-what-is-postgresql-used-for\">Q.1: What is PostgreSQL used for?<\/a><\/li><li><a href=\"#q2-what-are-the-features-of-postgresql\">Q.2: What are the Features of PostgreSQL?<\/a><\/li><li><a href=\"#q3-how-do-i-access-the-postgresql-database\">Q.3: How do I access the PostgreSQL database?<\/a><\/li><\/ul><li><a href=\"#additional-resources\">Additional Resources<\/a><\/li><\/ul><\/div><\/div><\/div><\/div>\n\n\n\n<p>PostgreSQL is a powerful, open-source object-relational database system that has a solid reputation for stability, feature robustness, and performance after more than 30 years of active development. PostgreSQL is used to store, manipulate and display the data in an application.PostgreSQL is used as a primary database for many web and mobile applications. PostgreSQL is very popular in tech giants like Apple which uses it for storing data for their users.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img  loading=\"lazy\"  src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEUAAP+KeNJXAAAAAXRSTlMAQObYZgAAAAlwSFlzAAAOxAAADsQBlSsOGwAAAApJREFUCNdjYAAAAAIAAeIhvDMAAAAASUVORK5CYII=\"  alt=\"PostgreSQL\"  class=\"wp-image-7555 pk-lazyload\"  width=\"227\"  height=\"256\"  data-pk-sizes=\"auto\"  data-ls-sizes=\"(max-width: 227px) 100vw, 227px\"  data-pk-src=\"https:\/\/www.interviewbit.com\/blog\/wp-content\/uploads\/2022\/03\/PostgreSQL-909x1024.png\"  data-pk-srcset=\"https:\/\/www.interviewbit.com\/blog\/wp-content\/uploads\/2022\/03\/PostgreSQL-909x1024.png 909w, https:\/\/www.interviewbit.com\/blog\/wp-content\/uploads\/2022\/03\/PostgreSQL-266x300.png 266w, https:\/\/www.interviewbit.com\/blog\/wp-content\/uploads\/2022\/03\/PostgreSQL-768x865.png 768w, https:\/\/www.interviewbit.com\/blog\/wp-content\/uploads\/2022\/03\/PostgreSQL-380x428.png 380w, https:\/\/www.interviewbit.com\/blog\/wp-content\/uploads\/2022\/03\/PostgreSQL-550x620.png 550w, https:\/\/www.interviewbit.com\/blog\/wp-content\/uploads\/2022\/03\/PostgreSQL-800x901.png 800w, https:\/\/www.interviewbit.com\/blog\/wp-content\/uploads\/2022\/03\/PostgreSQL.png 1072w\" ><\/figure><\/div>\n\n\n\n<p>There are several applications of PostgreSQL :<\/p>\n\n\n\n<ol><li><strong>Financial Industry:<\/strong> PostgreSQL is an excellent database management system for the financial sector. Furthermore, it is fully ACID compliant, making it an excellent alternative for OLTP (Online Transaction Processing).<\/li><li><strong>Government GIS Data: <\/strong>PostgreSQL comes with a robust GIS named &#8220;PostGIS.&#8221; This addon contains hundreds of functions to process geometric data in multiple formats. PostGIS adheres to several industry standards.<\/li><li><strong>Manufacturing: <\/strong>PostgreSQL is now being used by industrial businesses to improve their overall business processes. It enables businesses to cut down on their operational costs.<\/li><li><strong>Web technology and NoSQL:<\/strong> Scalability is a major concern if your website must handle hundreds or even thousands of requests per second at any given time. Postgre proves to be the best option in this case.<\/li><\/ol>\n\n\n\n<p>In this blog, we will be learning about PostgreSQL commands. We will learn to build a connection to the database, using INSERT, SELECT, CREATE commands for insertion, reading and creation of values and tables in the database.<\/p>\n\n\n\n<p>We will be executing these commands in a PostgresSQL shell, you should have the PostgreSQL installed on your device before moving forward. You can download PostgreSQL based on your Operating System on this site: <a href=\"https:\/\/www.postgresql.org\/download\/\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/www.postgresql.org\/download\/<\/a><\/p>\n\n\n\n<p>Now you have the PostgreSQL available to you. The next step is to start the PostgreSQL server using&nbsp;<\/p>\n\n\n\n<ol><li><strong>Start PostgreSQL Server\/Initialize the Database<\/strong><\/li><\/ol>\n\n\n\n<p><strong>Command (To initialize):<\/strong> sudo service postgresql-9.3 initdb(linux)<\/p>\n\n\n\n<p><strong>Command (To start): <\/strong>sudo service postgresql-9.3 start(linux)<\/p>\n\n\n\n<p>Note: Make sure to have the environment variables for postgres set before executing the command to prevent undefined errors<\/p>\n\n\n\n<ol start=\"2\"><li><strong>Stop PostgreSQL Server\/Initialize the Database<\/strong><\/li><\/ol>\n\n\n\n<p><strong>Command: <\/strong>sudo service postgresql-9.3 stop(linux)<\/p>\n\n\n\n<p>The PostgreSQL is up and running on your machine, let us create a new connection in the database server and set up a database along with other useful commands in PostgreSQL. Below is a list of the most common and useful commands in PostgreSQL.<\/p>\n\n\n\n<h2 id=\"postgresql-commands-list\">PostgreSQL Commands List<\/h2>\n\n\n\n<h3 id=\"1-connect-to-postgresql-database\">1. Connect to PostgreSQL Database<\/h3>\n\n\n\n<p>The following command establishes a connection to a database under the control of a specified user. After pressing Enter, PostgreSQL will prompt for the user&#8217;s password.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"sql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">psql -d database -U  user -W<\/pre>\n\n\n\n<p>To connect to the user_db database as a Postgres user, for example, execute the following command:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"sql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">C:\\Program Files\\PostgreSQL\\9.5\\bin>psql -d user_dbl -U postgres -W\nPassword for user postgres:\nuser_db=#<\/pre>\n\n\n\n<p>If you want to connect to a database that is hosted on a different server, use the -h option:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"sql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">psql -h host -d database -U user -W<\/pre>\n\n\n\n<p>If you want to use SSL mode for the connection, simply specify it as seen in the command below:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"sql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">psql -U user -h host \"dbname=db sslmode=require\"<\/pre>\n\n\n\n<h3 id=\"2-change-the-database-connection-to-a-new-one\">2. Change the database connection to a new one<\/h3>\n\n\n\n<p>You can switch the connection to a new database while logged in with an existing user. The previously established connection will be terminated. If the user parameter is omitted, the current user is assumed.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"sql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\\c dbname username\n<\/pre>\n\n\n\n<p>Under the Postgres user, run the following command to connect to the user_db database:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"sql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">postgres=# \\c user_db\nYou are now connected to database \"user_db\" as user \"postgres\".\nuser_ab=#<\/pre>\n\n\n\n<h3 id=\"3-list-available-database\">3. List available database<\/h3>\n\n\n\n<p>The command is used to list all databases in the current PostgreSQL database server:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"sql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\\l<\/pre>\n\n\n\n<h3 id=\"4-list-available-table\">4. List available table<\/h3>\n\n\n\n<p>The \\dt command is used to list all tables in the current database:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"sql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\\dt<\/pre>\n\n\n\n<p>This command only displays the table in the currently connected database.<\/p>\n\n\n\n<h3 id=\"5-describe-table\">5. Describe table<\/h3>\n\n\n\n<p>The following command is used to describe a table, such as a column, data type, column modifiers, and so on:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"sql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\\d table_name<\/pre>\n\n\n\n<h3 id=\"6-list-available-schema\">6. List available schema<\/h3>\n\n\n\n<p><strong><\/strong>A database schema represents the logical configuration of all or part of a relational database.&nbsp;<\/p>\n\n\n\n<p>The \\dn command is used to list all schemas in the currently connected database.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"sql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\\dn<\/pre>\n\n\n\n<h3 id=\"7-list-available-function\">7. List available function<\/h3>\n\n\n\n<p>The \\df command is used to display a list of available functions in the current database. In pg catalog there are several functions. We can list them using \\df.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"sql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\\df<\/pre>\n\n\n\n<h3 id=\"8-list-all-views\">8. List all views<\/h3>\n\n\n\n<p>The \\dv command is used to list all accessible views in the current database.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"sql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\\dv<\/pre>\n\n\n\n<h3 id=\"9-list-users-and-roles\">9. List users and roles<\/h3>\n\n\n\n<p>You can define users as superuser(admin) who can do anything and everything in the database. Or a user with limited powers like adding\/reading data only. You can use the \\du command to get a list of all users and their assigned roles:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"sql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"> \\du<\/pre>\n\n\n\n<h3 id=\"10-execute-the-previous-command\">10. Execute the previous command<\/h3>\n\n\n\n<p>To retrieve the current version of PostgreSQL server, you use the version() function as follows:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"sql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">SELECT version();<\/pre>\n\n\n\n<p><strong>Output :<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"sql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">postgres (PostgreSQL) 9.3.10<\/pre>\n\n\n\n<p>If you wish to save time by not having to type the preceding command twice, you can use the \\g command to do so:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"sql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\\g<\/pre>\n\n\n\n<p>The previous command, the SELECT statement, is repeated by psql.<\/p>\n\n\n\n<h3 id=\"11-command-history\">11. Command History<\/h3>\n\n\n\n<p>The \\s command is used to display command history. If you want to view the commands executed till now. Eg: database creation, table creation, table manipulation. You can use \/s to view all of them in one go.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"sql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\\s<\/pre>\n\n\n\n<p>If you want to store the command history to a file, use the following syntax to give the file name after the s command:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"sql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\\s filename<\/pre>\n\n\n\n<h3 id=\"12-execute-psql-commands\">12. Execute psql commands<\/h3>\n\n\n\n<p>If you want to run any psql command from a file, use the \\i command, which is as follows:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"sql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\\i filename<\/pre>\n\n\n\n<p>You can run any command written in a text file using \/i. For eg:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img  loading=\"lazy\"  width=\"1024\"  height=\"499\"  src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEUAAP+KeNJXAAAAAXRSTlMAQObYZgAAAAlwSFlzAAAOxAAADsQBlSsOGwAAAApJREFUCNdjYAAAAAIAAeIhvDMAAAAASUVORK5CYII=\"  alt=\"Execute psql commands\"  class=\"wp-image-7552 pk-lazyload\"  data-pk-sizes=\"auto\"  data-ls-sizes=\"(max-width: 1024px) 100vw, 1024px\"  data-pk-src=\"https:\/\/www.interviewbit.com\/blog\/wp-content\/uploads\/2022\/03\/Execute-psql-commands-1024x499.png\"  data-pk-srcset=\"https:\/\/www.interviewbit.com\/blog\/wp-content\/uploads\/2022\/03\/Execute-psql-commands-1024x499.png 1024w, https:\/\/www.interviewbit.com\/blog\/wp-content\/uploads\/2022\/03\/Execute-psql-commands-300x146.png 300w, https:\/\/www.interviewbit.com\/blog\/wp-content\/uploads\/2022\/03\/Execute-psql-commands-768x374.png 768w, https:\/\/www.interviewbit.com\/blog\/wp-content\/uploads\/2022\/03\/Execute-psql-commands-1536x749.png 1536w, https:\/\/www.interviewbit.com\/blog\/wp-content\/uploads\/2022\/03\/Execute-psql-commands-2048x998.png 2048w, https:\/\/www.interviewbit.com\/blog\/wp-content\/uploads\/2022\/03\/Execute-psql-commands-380x185.png 380w, https:\/\/www.interviewbit.com\/blog\/wp-content\/uploads\/2022\/03\/Execute-psql-commands-550x268.png 550w, https:\/\/www.interviewbit.com\/blog\/wp-content\/uploads\/2022\/03\/Execute-psql-commands-800x390.png 800w, https:\/\/www.interviewbit.com\/blog\/wp-content\/uploads\/2022\/03\/Execute-psql-commands-1160x565.png 1160w\" ><\/figure>\n\n\n\n<p>This command can be executed in the command line using \/i command.<\/p>\n\n\n\n<h3 id=\"13-get-help-on-psql-commands\">13. Get help on psql commands<\/h3>\n\n\n\n<p>The \\? command displays a list of all accessible psql commands.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"sql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\\?<\/pre>\n\n\n\n<p>The \\h command is used to seek help on certain PostgreSQL statements.<\/p>\n\n\n\n<p>For instance, if you wish to learn more about the ALTER TABLE statement, you can execute the following command:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"sql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\\h ALTER TABLE<\/pre>\n\n\n\n<h3 id=\"14-turn-on-query-execution-time\">14. Turn on query execution time<\/h3>\n\n\n\n<p>The \\timing command is used to enable query execution time. This command helps you know the execution time of the query. For eg : 1.495ms for the below example.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"sql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">user_ab=# \\timing\nTiming is on.\nuser_ab=# select count(*) from film;\n count\n-------\n  1000\n(1 row)\n\nTime: 1.495 ms\nuser_ab=#<\/pre>\n\n\n\n<p>You use the same command \\timing to turn it off.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"sql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">user_db=# \\timing\nTiming is off.\nuser_db=#<\/pre>\n\n\n\n<h3 id=\"15-edit-command-in-your-editor\">15. Edit command in your editor<\/h3>\n\n\n\n<p>It&#8217;s quite convenient if you can type the command in your preferred editor. You use the \\e command in psql to accomplish this. Following the command, psql will launch the text editor specified by your EDITOR environment variable and paste the most recent command you typed into it.<\/p>\n\n\n\n<p>psql will execute the command and return the result once you type it in the editor, save it, and shut it.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"sql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\\ef [function name]<\/pre>\n\n\n\n<h3 id=\"16-switch-output-options\">16. Switch output options<\/h3>\n\n\n\n<p>psql will execute the command and return the result once you type it in the editor,&nbsp; &nbsp; save it, and shut it.<\/p>\n\n\n\n<ul><li>&nbsp;\\a command fixes the alignment of the output.<\/li><li>&nbsp;\\H command formats the output in HTML form.<\/li><\/ul>\n\n\n\n<h3 id=\"17-quit-psql\">17. Quit psql<\/h3>\n\n\n\n<p>To quit psql, you use \\q command and press enter to exit psql.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"sql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\\q<\/pre>\n\n\n\n<p>In this tutorial, we learnt about PostgreSQL. We discussed the major features of PostgreSQL which led to its wide usage among several industries. We try to understand multiple commands for different functions in PostgreSQL like establishing the connection and showing the databases and tables created in it. Now you know how to get started with PostgreSQL on your machine.<\/p>\n\n\n\n<h2 id=\"faqs\">FAQs<\/h2>\n\n\n\n<h3 id=\"q1-what-is-postgresql-used-for\"><span id=\"q-1-what-is-postgresql-used-for\">Q.1: What is PostgreSQL used for?<\/span><\/h3>\n\n\n\n<p><strong>Ans: <\/strong>Many web, mobile, geospatial, and analytics applications use PostgreSQL as their primary data storage or data warehouse. PostgreSQL 12 is the most recent major version.<\/p>\n\n\n\n<h3 id=\"q2-what-are-the-features-of-postgresql\"><span id=\"q-2-what-are-the-features-of-postgresql\">Q.2: What are the Features of PostgreSQL?<\/span><\/h3>\n\n\n\n<p><strong>Ans:<\/strong> PostgreSQL is a powerful, open-source object-relational database system that has a solid reputation in stability, feature robustness, and performance.<\/p>\n\n\n\n<h3 id=\"q3-how-do-i-access-the-postgresql-database\"><span id=\"q-3-how-do-i-access-the-postgresql-database\">Q.3: How do I access the PostgreSQL database?<\/span><\/h3>\n\n\n\n<p><strong>Ans:<\/strong> You can connect to the database using<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"sql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">psql -d database -U  user<\/pre>\n\n\n\n<p>-u signifies user<br>-d signifies database<\/p>\n\n\n\n<h2 id=\"additional-resources\">Additional Resources<\/h2>\n\n\n\n<ul><li><a href=\"https:\/\/www.interviewbit.com\/sql-interview-questions\/#postgresql\" target=\"_blank\" rel=\"noreferrer noopener\">PostgreSQL Interview Questions<\/a><\/li><li><a href=\"https:\/\/www.interviewbit.com\/blog\/postgresql-vs-mysql\/\" target=\"_blank\" rel=\"noreferrer noopener\">PostgreSQL vs MySQL<\/a><\/li><\/ul>\n","protected":false},"excerpt":{"rendered":"PostgreSQL is a powerful, open-source object-relational database system that has a solid reputation for stability, feature robustness, and&hellip;\n","protected":false},"author":4,"featured_media":7554,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_daextam_enable_autolinks":"1","csco_singular_sidebar":"","csco_page_header_type":"","csco_appearance_grid":"","csco_page_load_nextpost":"","csco_post_video_location":[],"csco_post_video_location_hash":"","csco_post_video_url":"","csco_post_video_bg_start_time":0,"csco_post_video_bg_end_time":0},"categories":[748],"tags":[503,1174],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.interviewbit.com\/blog\/wp-json\/wp\/v2\/posts\/7549"}],"collection":[{"href":"https:\/\/www.interviewbit.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.interviewbit.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.interviewbit.com\/blog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.interviewbit.com\/blog\/wp-json\/wp\/v2\/comments?post=7549"}],"version-history":[{"count":6,"href":"https:\/\/www.interviewbit.com\/blog\/wp-json\/wp\/v2\/posts\/7549\/revisions"}],"predecessor-version":[{"id":19961,"href":"https:\/\/www.interviewbit.com\/blog\/wp-json\/wp\/v2\/posts\/7549\/revisions\/19961"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.interviewbit.com\/blog\/wp-json\/wp\/v2\/media\/7554"}],"wp:attachment":[{"href":"https:\/\/www.interviewbit.com\/blog\/wp-json\/wp\/v2\/media?parent=7549"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.interviewbit.com\/blog\/wp-json\/wp\/v2\/categories?post=7549"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.interviewbit.com\/blog\/wp-json\/wp\/v2\/tags?post=7549"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}