{"id":687,"date":"2019-08-25T10:46:14","date_gmt":"2019-08-25T05:16:14","guid":{"rendered":"http:\/\/uitutorials.in\/wp\/?p=687"},"modified":"2019-08-25T10:46:14","modified_gmt":"2019-08-25T05:16:14","slug":"postgres-command-line","status":"publish","type":"post","link":"https:\/\/uitutorials.in\/wp\/postgres-command-line\/","title":{"rendered":"Postgres Command Line"},"content":{"rendered":"<p>psql: FATAL: password authentication failed for user error while trying to access psql<br \/>\nAns<br \/>\npsql by default will use the same username as your OS session is using. You need to first login as postgres or switch to<br \/>\nits user (assuming it exists): su &#8211; postgres or explicitly type username for psql  psql -U postgres.<\/p>\n<p>Login User  : <\/p>\n<pre class=\"line-numbers\"><code class=\"language-sql\">psql -U postgres<\/code><\/pre>\n<p>log in with <\/p>\n<pre class=\"line-numbers\"><code class=\"language-sql\">psql --username=postgres<\/code><\/pre>\n<p>Backup Restore : <\/p>\n<p>Note : Before restore db we should have the database <\/p>\n<pre class=\"line-numbers\"><code class=\"language-sql\">\"postgres=# CREATE DATABASE employee;\"<\/code><\/pre>\n<p>.<\/p>\n<pre class=\"line-numbers\"><code class=\"language-sql\">\r\npsql -h localhost -U postgres -p 5432 sqlex &lt; sqlexbackup.sql (postgres=# CREATE DATABASE sqlex;)\r\npsql -h localhost -U postgres -p 5432 northwind &lt; northwindexbackup.sql (postgres=# CREATE DATABASE northwind; - northwind_user)\r\npsql -h localhost -U postgres -p 5432 employee &lt; empexbackup.sql (postgres=# CREATE DATABASE employee;)\r\n\r\nD:\\PostgreSQL\\sqlex&gt;psql -h localhost -U postgres -p 5432 sqlex &lt; sqlexbackup.sql\r\n\r\npsql -h localhost -U postgres -p 5432 my_new_database &lt; my_old_database.backup\r\npsql \"dbname=sqlex host=localhost user=postgres password=abc port=5432\"\r\n<\/code><\/pre>\n<p><a href=\"https:\/\/stackoverflow.com\/questions\/2732474\/restore-a-postgres-backup-file-using-the-command-line\" rel=\"noopener\" target=\"_blank\">Click<\/a><\/p>\n<pre class=\"line-numbers\"><code class=\"language-sql\">\r\nlist user : \\du\r\n\r\n\\l+ to list databases\r\n\\d+ to list all tables in current search_path schema in current database.\r\npsql -U pgadmin -l\r\n\r\n\r\nTo switch databases:\r\n\\connect database_name or \\c database_name\r\n\r\n\r\nCreate User : \r\npsql -U postgres -c \"CREATE USER my_app CREATEDB PASSWORD 'my_password'\"\r\n\r\npsql -U postgres -c \"CREATE USER user3 CREATEDB PASSWORD 'abc'\"\r\npsql -U postgres -c \"CREATE USER northwind_user CREATEDB PASSWORD 'abc'\"\r\npsql -U postgres -c \"CREATE USER emp CREATEDB PASSWORD 'abc'\"\r\n<\/code><\/pre>\n<p><strong>Example<\/strong><\/p>\n<pre class=\"line-numbers\"><code class=\"language-sql\">\r\nD:\\PostgreSQL\\sqlex>psql -U postgres\r\nPassword for user postgres:\r\npsql (11.0)\r\nWARNING: Console code page (437) differs from Windows code page (1252)\r\n         8-bit characters might not work correctly. See psql reference\r\n         page \"Notes for Windows users\" for details.\r\nType \"help\" for help.\r\n\r\npostgres=# create database sqlex;\r\nCREATE DATABASE\r\npostgres=#\r\n<\/code><\/pre>\n<p>https:\/\/www.w3resource.com\/PostgreSQL\/postgresql-backup-restore.php<br \/>\nhttps:\/\/itnext.io\/ngrx-best-practices-for-enterprise-angular-applications-6f00bcdf36d7<\/p>\n","protected":false},"excerpt":{"rendered":"<p>psql: FATAL: password authentication failed for user error while trying to access psql Ans psql by default will use the same username as your OS session is using. You need to first login as postgres or switch to its user (assuming it exists): su &#8211; postgres or explicitly type username<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[80],"tags":[82],"class_list":["post-687","post","type-post","status-publish","format-standard","hentry","category-sql","tag-postgresql","ct-col-2"],"_links":{"self":[{"href":"https:\/\/uitutorials.in\/wp\/wp-json\/wp\/v2\/posts\/687","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/uitutorials.in\/wp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/uitutorials.in\/wp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/uitutorials.in\/wp\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/uitutorials.in\/wp\/wp-json\/wp\/v2\/comments?post=687"}],"version-history":[{"count":2,"href":"https:\/\/uitutorials.in\/wp\/wp-json\/wp\/v2\/posts\/687\/revisions"}],"predecessor-version":[{"id":689,"href":"https:\/\/uitutorials.in\/wp\/wp-json\/wp\/v2\/posts\/687\/revisions\/689"}],"wp:attachment":[{"href":"https:\/\/uitutorials.in\/wp\/wp-json\/wp\/v2\/media?parent=687"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/uitutorials.in\/wp\/wp-json\/wp\/v2\/categories?post=687"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/uitutorials.in\/wp\/wp-json\/wp\/v2\/tags?post=687"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}