{"id":151,"date":"2017-11-22T10:30:17","date_gmt":"2017-11-22T10:30:17","guid":{"rendered":"https:\/\/blinksql.com\/?p=151"},"modified":"2017-11-22T10:30:17","modified_gmt":"2017-11-22T10:30:17","slug":"postgresql-database-administration-commands","status":"publish","type":"post","link":"https:\/\/blinksql.com\/?p=151","title":{"rendered":"PostgreSQL Database Administration Commands"},"content":{"rendered":"<p><strong>Version of PostgreSQL:<\/strong><br \/>\n<strong>cmd:select version();<br \/>\n<\/strong><br \/>\n<img fetchpriority=\"high\" decoding=\"async\" src=\"https:\/\/blinksql.com\/wp-content\/uploads\/2017\/11\/to-know-the-version-of-postgres.png\" alt=\"to know the version of postgres\" width=\"977\" height=\"198\" class=\"alignnone size-full wp-image-152\" \/><\/p>\n<p><strong>Creating the user in the shell prompt:<br \/>\n<\/strong><br \/>\n<strong>cmd:create user postgres_user;<br \/>\n<\/strong><br \/>\n<img decoding=\"async\" src=\"https:\/\/blinksql.com\/wp-content\/uploads\/2017\/11\/create-user.png\" alt=\"create user\" width=\"425\" height=\"47\" class=\"alignnone size-full wp-image-153\" \/><\/p>\n<p><strong>Creating the database in the shell prompt:<br \/>\n<\/strong><br \/>\n<strong>cmd:<br \/>\n\/usr\/local\/pgsql\/bin\/createdb my_db -O postgres -p 5435;<\/strong><br \/>\n<img decoding=\"async\" src=\"https:\/\/blinksql.com\/wp-content\/uploads\/2017\/11\/create-db-in-psql.png\" alt=\"create db in psql\" width=\"659\" height=\"20\" class=\"alignnone size-full wp-image-154\" \/><\/p>\n<p><strong>-&gt; To query the created database use the cmd:<br \/>\n<\/strong><br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/blinksql.com\/wp-content\/uploads\/2017\/11\/switch-to-the-db1.png\" alt=\"switch to the db\" width=\"601\" height=\"71\" class=\"alignnone size-full wp-image-155\" \/><\/p>\n<p><strong>Get a list of databases in a Postgresql database:<br \/>\n<\/strong><br \/>\ncmd:\\l<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/blinksql.com\/wp-content\/uploads\/2017\/11\/to-list-the-databases.png\" alt=\"to list the databases\" width=\"705\" height=\"246\" class=\"alignnone size-full wp-image-156\" \/><\/p>\n<p><strong>Delete\/Drop an existing PostgreSQL database:<br \/>\n<\/strong><br \/>\ncmd:DROP DATABASE test;<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/blinksql.com\/wp-content\/uploads\/2017\/11\/drop-database.png\" alt=\"drop database\" width=\"277\" height=\"55\" class=\"alignnone size-full wp-image-157\" \/><\/p>\n<p><strong>Getting help on postgreSQL commands:<br \/>\n<\/strong><br \/>\n-&gt; We can get the syantax for create,delete,index etc. by using the \\h and the required syntax name.<br \/>\ncmd:\\h CREATE<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/blinksql.com\/wp-content\/uploads\/2017\/11\/create-cmd-help.png\" alt=\"create cmd help\" width=\"700\" height=\"304\" class=\"alignnone size-full wp-image-158\" \/><\/p>\n<p><strong>Get a list of all the tables in a Postgresql database:<\/strong><br \/>\ncmd: \\d<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/blinksql.com\/wp-content\/uploads\/2017\/11\/list-of-tables.png\" alt=\"list of tables\" width=\"823\" height=\"287\" class=\"alignnone size-full wp-image-159\" \/><\/p>\n<p><strong>To turn on timing, and checking how much time a query takes to execute:<\/strong><br \/>\n-&gt; After this if you execute a query it will show how much time it took for doing it.<br \/>\ncmd:\\timing<br \/>\ncmd:select * from attribute_master_abstract limit 2;<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/blinksql.com\/wp-content\/uploads\/2017\/11\/to-know-the-query-execution-time.png\" alt=\"to know the query execution time\" width=\"1075\" height=\"210\" class=\"alignnone size-full wp-image-160\" \/><\/p>\n<p><strong>To see the list of available functions in PostgreSQL:<br \/>\n<\/strong><br \/>\ncmd:\\df or \\df+<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Version of PostgreSQL: cmd:select version(); Creating the user in the shell prompt: cmd:create user postgres_user; Creating the database in the shell prompt: cmd: \/usr\/local\/pgsql\/bin\/createdb my_db -O postgres -p 5435; -&gt;&hellip;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_eb_attr":""},"categories":[1],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v19.10 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>PostgreSQL Database Administration Commands - Blink SQL<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/blinksql.com\/?p=151\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"PostgreSQL Database Administration Commands - Blink SQL\" \/>\n<meta property=\"og:description\" content=\"Version of PostgreSQL: cmd:select version(); Creating the user in the shell prompt: cmd:create user postgres_user; Creating the database in the shell prompt: cmd: \/usr\/local\/pgsql\/bin\/createdb my_db -O postgres -p 5435; -&gt;&hellip;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/blinksql.com\/?p=151\" \/>\n<meta property=\"og:site_name\" content=\"Blink SQL\" \/>\n<meta property=\"article:published_time\" content=\"2017-11-22T10:30:17+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/blinksql.com\/wp-content\/uploads\/2017\/11\/to-know-the-version-of-postgres.png\" \/>\n<meta name=\"author\" content=\"Hannie\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@harika_sanaka\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Hannie\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/blinksql.com\/?p=151#article\",\"isPartOf\":{\"@id\":\"https:\/\/blinksql.com\/?p=151\"},\"author\":{\"name\":\"Hannie\",\"@id\":\"https:\/\/blinksql.com\/#\/schema\/person\/f04b99304f59e14956e768e764d2afd4\"},\"headline\":\"PostgreSQL Database Administration Commands\",\"datePublished\":\"2017-11-22T10:30:17+00:00\",\"dateModified\":\"2017-11-22T10:30:17+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/blinksql.com\/?p=151\"},\"wordCount\":169,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/blinksql.com\/#organization\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/blinksql.com\/?p=151#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/blinksql.com\/?p=151\",\"url\":\"https:\/\/blinksql.com\/?p=151\",\"name\":\"PostgreSQL Database Administration Commands - Blink SQL\",\"isPartOf\":{\"@id\":\"https:\/\/blinksql.com\/#website\"},\"datePublished\":\"2017-11-22T10:30:17+00:00\",\"dateModified\":\"2017-11-22T10:30:17+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/blinksql.com\/?p=151#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/blinksql.com\/?p=151\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/blinksql.com\/?p=151#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/blinksql.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PostgreSQL Database Administration Commands\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/blinksql.com\/#website\",\"url\":\"https:\/\/blinksql.com\/\",\"name\":\"Blink SQL\",\"description\":\" Thinking SQL\",\"publisher\":{\"@id\":\"https:\/\/blinksql.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/blinksql.com\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/blinksql.com\/#organization\",\"name\":\"Blink SQL\",\"url\":\"https:\/\/blinksql.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/blinksql.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/blinksql.com\/wp-content\/uploads\/2022\/11\/cropped-BlinkSQL-removebg.png\",\"contentUrl\":\"https:\/\/blinksql.com\/wp-content\/uploads\/2022\/11\/cropped-BlinkSQL-removebg.png\",\"width\":280,\"height\":172,\"caption\":\"Blink SQL\"},\"image\":{\"@id\":\"https:\/\/blinksql.com\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/blinksql.com\/#\/schema\/person\/f04b99304f59e14956e768e764d2afd4\",\"name\":\"Hannie\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/blinksql.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/c5876b3497d2c2eb98256b7c183220c1?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/c5876b3497d2c2eb98256b7c183220c1?s=96&d=mm&r=g\",\"caption\":\"Hannie\"},\"sameAs\":[\"http:\/\/blinksql.com\",\"https:\/\/twitter.com\/harika_sanaka\"],\"url\":\"https:\/\/blinksql.com\/?author=2\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"PostgreSQL Database Administration Commands - Blink SQL","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/blinksql.com\/?p=151","og_locale":"en_US","og_type":"article","og_title":"PostgreSQL Database Administration Commands - Blink SQL","og_description":"Version of PostgreSQL: cmd:select version(); Creating the user in the shell prompt: cmd:create user postgres_user; Creating the database in the shell prompt: cmd: \/usr\/local\/pgsql\/bin\/createdb my_db -O postgres -p 5435; -&gt;&hellip;","og_url":"https:\/\/blinksql.com\/?p=151","og_site_name":"Blink SQL","article_published_time":"2017-11-22T10:30:17+00:00","og_image":[{"url":"https:\/\/blinksql.com\/wp-content\/uploads\/2017\/11\/to-know-the-version-of-postgres.png"}],"author":"Hannie","twitter_card":"summary_large_image","twitter_creator":"@harika_sanaka","twitter_misc":{"Written by":"Hannie","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/blinksql.com\/?p=151#article","isPartOf":{"@id":"https:\/\/blinksql.com\/?p=151"},"author":{"name":"Hannie","@id":"https:\/\/blinksql.com\/#\/schema\/person\/f04b99304f59e14956e768e764d2afd4"},"headline":"PostgreSQL Database Administration Commands","datePublished":"2017-11-22T10:30:17+00:00","dateModified":"2017-11-22T10:30:17+00:00","mainEntityOfPage":{"@id":"https:\/\/blinksql.com\/?p=151"},"wordCount":169,"commentCount":0,"publisher":{"@id":"https:\/\/blinksql.com\/#organization"},"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/blinksql.com\/?p=151#respond"]}]},{"@type":"WebPage","@id":"https:\/\/blinksql.com\/?p=151","url":"https:\/\/blinksql.com\/?p=151","name":"PostgreSQL Database Administration Commands - Blink SQL","isPartOf":{"@id":"https:\/\/blinksql.com\/#website"},"datePublished":"2017-11-22T10:30:17+00:00","dateModified":"2017-11-22T10:30:17+00:00","breadcrumb":{"@id":"https:\/\/blinksql.com\/?p=151#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/blinksql.com\/?p=151"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/blinksql.com\/?p=151#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/blinksql.com\/"},{"@type":"ListItem","position":2,"name":"PostgreSQL Database Administration Commands"}]},{"@type":"WebSite","@id":"https:\/\/blinksql.com\/#website","url":"https:\/\/blinksql.com\/","name":"Blink SQL","description":" Thinking SQL","publisher":{"@id":"https:\/\/blinksql.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/blinksql.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/blinksql.com\/#organization","name":"Blink SQL","url":"https:\/\/blinksql.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/blinksql.com\/#\/schema\/logo\/image\/","url":"https:\/\/blinksql.com\/wp-content\/uploads\/2022\/11\/cropped-BlinkSQL-removebg.png","contentUrl":"https:\/\/blinksql.com\/wp-content\/uploads\/2022\/11\/cropped-BlinkSQL-removebg.png","width":280,"height":172,"caption":"Blink SQL"},"image":{"@id":"https:\/\/blinksql.com\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/blinksql.com\/#\/schema\/person\/f04b99304f59e14956e768e764d2afd4","name":"Hannie","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/blinksql.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/c5876b3497d2c2eb98256b7c183220c1?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c5876b3497d2c2eb98256b7c183220c1?s=96&d=mm&r=g","caption":"Hannie"},"sameAs":["http:\/\/blinksql.com","https:\/\/twitter.com\/harika_sanaka"],"url":"https:\/\/blinksql.com\/?author=2"}]}},"_links":{"self":[{"href":"https:\/\/blinksql.com\/index.php?rest_route=\/wp\/v2\/posts\/151"}],"collection":[{"href":"https:\/\/blinksql.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blinksql.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blinksql.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blinksql.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=151"}],"version-history":[{"count":0,"href":"https:\/\/blinksql.com\/index.php?rest_route=\/wp\/v2\/posts\/151\/revisions"}],"wp:attachment":[{"href":"https:\/\/blinksql.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=151"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blinksql.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=151"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blinksql.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=151"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}