{"id":48892,"date":"2024-09-23T12:30:00","date_gmt":"2024-09-23T17:30:00","guid":{"rendered":"https:\/\/www.rosehosting.com\/blog\/?p=48892"},"modified":"2024-08-27T09:01:04","modified_gmt":"2024-08-27T14:01:04","slug":"psql-connect-to-database-how-to-manage-postgresql-from-the-command-line","status":"publish","type":"post","link":"https:\/\/www.rosehosting.com\/blog\/psql-connect-to-database-how-to-manage-postgresql-from-the-command-line\/","title":{"rendered":"PSQL Connect to Database: How to Manage PostgreSQL from the Command Line"},"content":{"rendered":"<div id=\"bsf_rt_marker\"><\/div>\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"1024\" height=\"576\" src=\"https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2024\/09\/PSQL-Connect-to-Database-How-to-manage-PostgreSQL-from-the-command-line.webp\" alt=\"How to Manage PostgreSQL from the command line with PSQL Connect to Database?\" class=\"wp-image-49110\" srcset=\"https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2024\/09\/PSQL-Connect-to-Database-How-to-manage-PostgreSQL-from-the-command-line.webp 1024w, https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2024\/09\/PSQL-Connect-to-Database-How-to-manage-PostgreSQL-from-the-command-line-300x169.webp 300w, https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2024\/09\/PSQL-Connect-to-Database-How-to-manage-PostgreSQL-from-the-command-line-150x84.webp 150w, https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2024\/09\/PSQL-Connect-to-Database-How-to-manage-PostgreSQL-from-the-command-line-768x432.webp 768w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Relational database management systems are a key component of many websites and applications. They provide a structured way to store data and access information in a structured way. PostgreSQL is a relational database management system (RDBMS) that implements the SQL query language. It is a popular choice for many small and large projects because it has many advanced features, such as reliable transactions and concurrency without read locks. This article will show how to manage PostgreSQL from the command line, commonly referred to as PSQL connect to database.<\/p>\n\n\n\n<!--more-->\n\n\n\n<h3 class=\"wp-block-heading\">Conventions<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\"># \u2013 given commands should be executed with root privileges either directly as a root user or by use of sudo command<br>$ \u2013 given commands should be executed as a regular user<\/pre>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-transparent ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-69eb43a3f3895\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"ez-toc-cssicon\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-69eb43a3f3895\"  aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.rosehosting.com\/blog\/psql-connect-to-database-how-to-manage-postgresql-from-the-command-line\/#PostgreSQL-Roles-and-Databases\" >PostgreSQL Roles and Databases<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.rosehosting.com\/blog\/psql-connect-to-database-how-to-manage-postgresql-from-the-command-line\/#Log-in-to-the-PostgreSQL-Account\" >Log in to the PostgreSQL Account<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.rosehosting.com\/blog\/psql-connect-to-database-how-to-manage-postgresql-from-the-command-line\/#Access-the-PostgreSQL-Prompt-Without-Changing-Accounts\" >Access the PostgreSQL Prompt Without Changing Accounts<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.rosehosting.com\/blog\/psql-connect-to-database-how-to-manage-postgresql-from-the-command-line\/#Create-a-New-Role\" >Create a New Role<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.rosehosting.com\/blog\/psql-connect-to-database-how-to-manage-postgresql-from-the-command-line\/#Create-a-New-Database\" >Create a New Database<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.rosehosting.com\/blog\/psql-connect-to-database-how-to-manage-postgresql-from-the-command-line\/#Open-a-Postgres-Prompt-with-a-New-Role\" >Open a Postgres Prompt with a New Role<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.rosehosting.com\/blog\/psql-connect-to-database-how-to-manage-postgresql-from-the-command-line\/#Create-and-Delete-Tables\" >Create and Delete Tables<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.rosehosting.com\/blog\/psql-connect-to-database-how-to-manage-postgresql-from-the-command-line\/#Add-Query-and-Delete-Data-In-a-Table\" >Add, Query, and Delete Data In a Table<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/www.rosehosting.com\/blog\/psql-connect-to-database-how-to-manage-postgresql-from-the-command-line\/#How-to-Add-and-Remove-Columns-from-a-Table\" >How to Add and Remove Columns from a Table<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/www.rosehosting.com\/blog\/psql-connect-to-database-how-to-manage-postgresql-from-the-command-line\/#How-to-Update-Data-in-a-Table\" >How to Update Data in a Table<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"PostgreSQL-Roles-and-Databases\"><\/span>PostgreSQL Roles and Databases<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Postgres uses a concept called &#8220;roles&#8221; to handle authentication and authorization. This concept is similar to regular Unix accounts, but Postgres uses the term &#8220;role&#8221; to distinguish between user privileges.<\/p>\n\n\n\n<p>Postgres is set up during installation with ident authentication, which means it associates roles with Unix\/Linux system accounts. If a role exists in Postgres, then a Unix\/Linux username with the same name can log in using that role.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Log-in-to-the-PostgreSQL-Account\"><\/span>Log in to the PostgreSQL Account<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The installation procedure creates an account named postgres with the Postgres role built into it. In order to use Postgres, we must log in to the system using that account.<\/p>\n\n\n\n<p>Log in to the postgres account on the server using:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ sudo -iu postgres<\/pre>\n\n\n\n<p>Now, we can access the PostgreSQL prompt with the command<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ psql<\/pre>\n\n\n\n<p>We can then login and interact with the database management system. To exit the PostgreSQL prompt, run this command, then hit ENTER:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\\q<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Access-the-PostgreSQL-Prompt-Without-Changing-Accounts\"><\/span>Access the PostgreSQL Prompt Without Changing Accounts<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>We can also run the desired commands directly through sudo. For example, in the previous example, we only want to log in to the Postgres prompt. We can log in to the postgres role with the current user using sudo:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ sudo -u postgres psql<\/pre>\n\n\n\n<p>This command will bring us into PostgreSQL without logging into one of its roles.<\/p>\n\n\n\n<p>We can exit with the command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\\q<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Create-a-New-Role\"><\/span>Create a New Role<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>After installing PostgreSQL server, we only have an existing postgres role with the database. We can create a new role using the createuser command. The &#8211;interactive flag will prompt for the required values.<\/p>\n\n\n\n<p>Let&#8217;s execute this command below to create a new PostgreSQL role:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ sudo -u postgres createuser --interactive<\/pre>\n\n\n\n<p>The command above will give you several options, and based on the response given, it will execute the PostgreSQL command needed to create a new user.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Enter name of role to add: master<br>Shall the new role be a superuser? (y\/n) y<\/pre>\n\n\n\n<p>We can provide more options with additional flags. Check the available options with the command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ man createuser<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Create-a-New-Database\"><\/span>Create a New Database<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The Postgres authentication system automatically creates a database with the same name as the role so that the role has access to it.<\/p>\n\n\n\n<p>Previously, we created a user named master who will automatically have access to the database named master. We can create the necessary database using the createdb command. If you are logged in using the postgres account, type the command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ createdb master<\/pre>\n\n\n\n<p>If you prefer to use sudo for each command without switching accounts, you can type:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ sudo -u postgres createdb master<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Open-a-Postgres-Prompt-with-a-New-Role\"><\/span>Open a Postgres Prompt with a New Role<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>To log in using ident-based authentication, you will need a Linux user with the same role name and the same Postgres database.<\/p>\n\n\n\n<p>If a user with the same name does not exist, you will need to create one using the adduser command. You will need to run this command with sudo privileges (not from postgres but from a normal Linux user):<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ sudo adduser master<\/pre>\n\n\n\n<p>Follow the steps on the screen when prompted, and once the required account is available, you can switch accounts and log in to the database using the command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ sudo -iu master<br>$ psql<\/pre>\n\n\n\n<p>Or you can also use the following one line:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ sudo -u master psql<\/pre>\n\n\n\n<p>You will be logged in automatically.<\/p>\n\n\n\n<p>If we want to connect to a different database than the current user, we can write the database name like this:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ psql -d postgres<\/pre>\n\n\n\n<p>Once logged in, we can check the connection information with the command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\\conninfo<\/pre>\n\n\n\n<p>You will see this as the output:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">You are connected to database \"master\" as user \"master\" via socket in \"\/var\/run\/postgresql\" at port \"5432\".<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Create-and-Delete-Tables\"><\/span>Create and Delete Tables<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Once we are connected to the PostgreSQL database system, we can perform some simple tasks. First, we will create a table to store data. Let&#8217;s create a table that describes a list of servers for a data center.<\/p>\n\n\n\n<p>The basic syntax for creating a table is as follows:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">CREATE TABLE table_name (<br>column_name1 col_type (field_length) column_constraints,<br>column_name2 col_type (field_length),<br>column_name3 col_type (field_length)<br>);<\/pre>\n\n\n\n<p>As you can see, we have written the table name, the desired columns, the column types, and the maximum data length that can be filled. We can also add constraints for each column if necessary.<\/p>\n\n\n\n<p>Now, we will create a table like this:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">CREATE TABLE datacenter (<br>equip_id serial PRIMARY KEY,<br>rackname varchar (50) NOT NULL,<br>color varchar (25) NOT NULL,<br>location varchar (25) check (location in ('north', 'south', 'west', 'east', 'northeast', 'southeast', 'southwest', 'northwest')),<br>install_date date<br>);<\/pre>\n\n\n\n<p>We have created a datacenter table to store our servers. This table has a serial type and an auto-incrementing integer. We can provide a primary key constraint for this column, meaning the content must be unique and not null.<\/p>\n\n\n\n<p>We do not provide a length for the two columns equip_id and install_date. This is because some column types do not require a maximum length.<\/p>\n\n\n\n<p>The rackname and color columns should not null. We also create a location column and a constraint to limit its value to 8 options. The last column is the install_date column which tells us when we installed it.<\/p>\n\n\n\n<p>We can see the newly created table with the command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\\d<\/pre>\n\n\n\n<p>You will see this after running the command above.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">                  List of relations<br> Schema |          Name           |   Type   | Owner  <br>--------+-------------------------+----------+--------<br> public | datacenter              | table    | master<br> public | datacenter_equip_id_seq | sequence | master<br>(2 rows)<\/pre>\n\n\n\n<p>We already have a datacenter table, but we also have another record called datacenter_equip_id_seq with a sequence type. This record represents the serial type that we gave earlier for the equip_id column. It will record the next number to automatically create data for columns of the serial type.<\/p>\n\n\n\n<p>If you want to see the table data without its sequence, type:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\\dt<\/pre>\n\n\n\n<p>You will see this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>          List of relations\n Schema |    Name    | Type  | Owner  \n--------+------------+-------+--------\n public | datacenter | table | master\n(1 row)<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Add-Query-and-Delete-Data-In-a-Table\"><\/span>Add, Query, and Delete Data In a Table<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>After having a table, we can insert data into it. We insert data by calling the table we want to add and giving the column names and data for each column.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">INSERT INTO datacenter (rackname, color, location, install_date) VALUES ('mercurius', 'red', 'south', '2020-02-16');<br>INSERT INTO datacenter (rackname, color, location, install_date) VALUES ('venus', 'grey', 'northwest', '2021-09-05');<\/pre>\n\n\n\n<p>There are a few things to note when entering data to minimize errors. First, the column name should not be marked with &#8221;, but the contents of the column need to be provided.<\/p>\n\n\n\n<p>We also need to avoid providing the equip_id column data manually. The contents will be created automatically.<\/p>\n\n\n\n<p>We can see the data that has been entered with the command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">SELECT * FROM datacenter;<\/pre>\n\n\n\n<p>Our output should be like this:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">equip_id | rackname | color | location | install_date<br>----------+-----------+-------+-----------+--------------<br>1 | mercurius | red | south | 2020-02-16<br>2 | venus | grey | northwest | 2021-09-05<br>(2 rows)<\/pre>\n\n\n\n<p>Here, we can see that the equip_id column already exists automatically, and the other data has been successfully added.<\/p>\n\n\n\n<p>If mercurius is no longer used and decommissioned, we have to delete it. To delete data from a table, use the command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">DELETE FROM datacenter WHERE rackname = 'mercurius';<\/pre>\n\n\n\n<p>If we want to see the contents of our table again, we will find that the slide is no longer there:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">SELECT * FROM datacenter;<\/pre>\n\n\n\n<p>And this is the output:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">equip_id | rackname | color | location | install_date<br>----------+----------+-------+-----------+--------------<br>2 | venus | grey | northwest | 2021-09-05<br>(1 row)<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How-to-Add-and-Remove-Columns-from-a-Table\"><\/span>How to Add and Remove Columns from a Table<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>We can add new columns to an existing table easily. We can add a column to display when the rackname was last maintained:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">ALTER TABLE datacenter ADD last_maint date;<\/pre>\n\n\n\n<p>To see the table information again, use the command (note the last column added):<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">SELECT * FROM datacenter;<\/pre>\n\n\n\n<p>You will see this:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">equip_id | rackname | color | location | install_date | last_maint<br>----------+----------+-------+-----------+--------------+------------<br>2 | venus | grey | northwest | 2021-09-05 |<br>(1 row)<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How-to-Update-Data-in-a-Table\"><\/span>How to Update Data in a Table<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>In the previous step, we learned how to add data to a table and delete it, but we didn&#8217;t discuss how to modify the existing data.<\/p>\n\n\n\n<p>For example, let&#8217;s say we want to retrieve data of type &#8220;venus&#8221; and change its color to red (this will replace all data of type &#8220;venus&#8221;):<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">UPDATE datacenter SET color = 'red' WHERE rackname = 'venus';<\/pre>\n\n\n\n<p>We can check that the command worked by:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">SELECT * FROM datacenter;<\/pre>\n\n\n\n<p>And this is the output:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">equip_id | rackname | color | location | install_date | last_maint<br>----------+----------+-------+-----------+--------------+------------<br>2 | venus | red | northwest | 2021-09-05 |<br>(1 row)<\/pre>\n\n\n\n<p>As you can see, the color has changed.<\/p>\n\n\n\n<p>Congratulation! You have learned about PSQL Connect to Database: How to Manage PostgreSQL from the Command Line. You should know the PostgreSQL basic commands now.<\/p>\n\n\n\n<p>Of course, if you are one of our <a href=\"https:\/\/www.rosehosting.com\/postgresql-hosting\/\" target=\"_blank\" rel=\"noreferrer noopener\">PostgreSQL Hosting<\/a> customers, you don\u2019t have to learn how to manage PostgreSQL from the command line yourself or even what people mean when they say PSQL connect to database. Ask our admins, sit back, and relax. They will help you manage your PostgreSQL database immediately and without any additional fee. Managing a PostgreSQL server is not just about the installation, we can help you with optimizing your PostgreSQL server if you have a VPS with us.<\/p>\n\n\n\n<p>If you liked our PSQL connect to database post using the command line, please share it with your friends and leave a comment below. Thanks.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Relational database management systems are a key component of many websites and applications. They provide a structured way to store &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"PSQL Connect to Database: How to Manage PostgreSQL from the Command Line\" class=\"read-more button\" href=\"https:\/\/www.rosehosting.com\/blog\/psql-connect-to-database-how-to-manage-postgresql-from-the-command-line\/#more-48892\" aria-label=\"Read more about PSQL Connect to Database: How to Manage PostgreSQL from the Command Line\">Read More<\/a><\/p>\n","protected":false},"author":4,"featured_media":49110,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1702],"tags":[41,2153,434,2182],"class_list":["post-48892","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-databases","tag-database","tag-how-to-2","tag-postgresql","tag-psql","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-33"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.4 (Yoast SEO v27.4) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>PSQL Connect to Database: Managing PostgreSQL | RoseHosting<\/title>\n<meta name=\"description\" content=\"What is PSQL Connect to Database? Learn how to manage PostgreSQL from the command line using our latest step-by-step guide.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.rosehosting.com\/blog\/psql-connect-to-database-how-to-manage-postgresql-from-the-command-line\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"PSQL Connect to Database: How to Manage PostgreSQL from the Command Line\" \/>\n<meta property=\"og:description\" content=\"PSQL Connect to Database: How to Manage PostgreSQL from the Command Line | RoseHosting\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.rosehosting.com\/blog\/psql-connect-to-database-how-to-manage-postgresql-from-the-command-line\/\" \/>\n<meta property=\"og:site_name\" content=\"RoseHosting\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/RoseHosting\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/rosehosting.helpdesk\" \/>\n<meta property=\"article:published_time\" content=\"2024-09-23T17:30:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2024\/09\/PSQL-Connect-to-Database-How-to-manage-PostgreSQL-from-the-command-line.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"1024\" \/>\n\t<meta property=\"og:image:height\" content=\"576\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\n<meta name=\"author\" content=\"Jeff Wilson\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@rosehosting\" \/>\n<meta name=\"twitter:site\" content=\"@rosehosting\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Jeff Wilson\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/psql-connect-to-database-how-to-manage-postgresql-from-the-command-line\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/psql-connect-to-database-how-to-manage-postgresql-from-the-command-line\\\/\"},\"author\":{\"name\":\"Jeff Wilson\",\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/#\\\/schema\\\/person\\\/7ce77a842fa6a9a7f8efa186f2353713\"},\"headline\":\"PSQL Connect to Database: How to Manage PostgreSQL from the Command Line\",\"datePublished\":\"2024-09-23T17:30:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/psql-connect-to-database-how-to-manage-postgresql-from-the-command-line\\\/\"},\"wordCount\":1372,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/psql-connect-to-database-how-to-manage-postgresql-from-the-command-line\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/wp-content\\\/uploads\\\/2024\\\/09\\\/PSQL-Connect-to-Database-How-to-manage-PostgreSQL-from-the-command-line.webp\",\"keywords\":[\"database\",\"how to\",\"PostgreSQL\",\"psql\"],\"articleSection\":[\"Databases\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/psql-connect-to-database-how-to-manage-postgresql-from-the-command-line\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/psql-connect-to-database-how-to-manage-postgresql-from-the-command-line\\\/\",\"url\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/psql-connect-to-database-how-to-manage-postgresql-from-the-command-line\\\/\",\"name\":\"PSQL Connect to Database: Managing PostgreSQL | RoseHosting\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/psql-connect-to-database-how-to-manage-postgresql-from-the-command-line\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/psql-connect-to-database-how-to-manage-postgresql-from-the-command-line\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/wp-content\\\/uploads\\\/2024\\\/09\\\/PSQL-Connect-to-Database-How-to-manage-PostgreSQL-from-the-command-line.webp\",\"datePublished\":\"2024-09-23T17:30:00+00:00\",\"description\":\"What is PSQL Connect to Database? Learn how to manage PostgreSQL from the command line using our latest step-by-step guide.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/psql-connect-to-database-how-to-manage-postgresql-from-the-command-line\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/psql-connect-to-database-how-to-manage-postgresql-from-the-command-line\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/psql-connect-to-database-how-to-manage-postgresql-from-the-command-line\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/wp-content\\\/uploads\\\/2024\\\/09\\\/PSQL-Connect-to-Database-How-to-manage-PostgreSQL-from-the-command-line.webp\",\"contentUrl\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/wp-content\\\/uploads\\\/2024\\\/09\\\/PSQL-Connect-to-Database-How-to-manage-PostgreSQL-from-the-command-line.webp\",\"width\":1024,\"height\":576,\"caption\":\"How to Manage PostgreSQL from the command line with PSQL Connect to Database?\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/psql-connect-to-database-how-to-manage-postgresql-from-the-command-line\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PSQL Connect to Database: How to Manage PostgreSQL from the Command Line\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/\",\"name\":\"RoseHosting.com\",\"description\":\"Premium Linux Tutorials Since 2001\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/#organization\",\"name\":\"RoseHosting\",\"url\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/03\\\/android-chrome-192x192-1.png\",\"contentUrl\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/03\\\/android-chrome-192x192-1.png\",\"width\":192,\"height\":192,\"caption\":\"RoseHosting\"},\"image\":{\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/RoseHosting\",\"https:\\\/\\\/x.com\\\/rosehosting\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/rosehosting\\\/\"],\"description\":\"RoseHosting is a leading Linux hosting provider, serving thousands of clients world-wide since 2001.\",\"email\":\"info@rosehosting.com\",\"telephone\":\"(314) 275-0414\",\"legalName\":\"Rose Web Services LLC\",\"foundingDate\":\"2001-04-02\",\"numberOfEmployees\":{\"@type\":\"QuantitativeValue\",\"minValue\":\"11\",\"maxValue\":\"50\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/#\\\/schema\\\/person\\\/7ce77a842fa6a9a7f8efa186f2353713\",\"name\":\"Jeff Wilson\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/0985fed6af04cc60703d2ecf27c65dfa373e0ca00eb21c0b03477e099ea3f99f?s=96&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/0985fed6af04cc60703d2ecf27c65dfa373e0ca00eb21c0b03477e099ea3f99f?s=96&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/0985fed6af04cc60703d2ecf27c65dfa373e0ca00eb21c0b03477e099ea3f99f?s=96&r=g\",\"caption\":\"Jeff Wilson\"},\"description\":\"An experienced Linux veteran with many years of experience. Helping other Linux admins with frequent Linux and business-related blog posts on the RoseHosting blog. Techie by choice. Loving nature and travel. Happily married and father of two lovely children.\",\"sameAs\":[\"https:\\\/\\\/www.rosehosting.com\",\"https:\\\/\\\/www.facebook.com\\\/rosehosting.helpdesk\"],\"url\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/author\\\/jwilson\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"PSQL Connect to Database: Managing PostgreSQL | RoseHosting","description":"What is PSQL Connect to Database? Learn how to manage PostgreSQL from the command line using our latest step-by-step guide.","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:\/\/www.rosehosting.com\/blog\/psql-connect-to-database-how-to-manage-postgresql-from-the-command-line\/","og_locale":"en_US","og_type":"article","og_title":"PSQL Connect to Database: How to Manage PostgreSQL from the Command Line","og_description":"PSQL Connect to Database: How to Manage PostgreSQL from the Command Line | RoseHosting","og_url":"https:\/\/www.rosehosting.com\/blog\/psql-connect-to-database-how-to-manage-postgresql-from-the-command-line\/","og_site_name":"RoseHosting","article_publisher":"https:\/\/www.facebook.com\/RoseHosting","article_author":"https:\/\/www.facebook.com\/rosehosting.helpdesk","article_published_time":"2024-09-23T17:30:00+00:00","og_image":[{"width":1024,"height":576,"url":"https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2024\/09\/PSQL-Connect-to-Database-How-to-manage-PostgreSQL-from-the-command-line.webp","type":"image\/webp"}],"author":"Jeff Wilson","twitter_card":"summary_large_image","twitter_creator":"@rosehosting","twitter_site":"@rosehosting","twitter_misc":{"Written by":"Jeff Wilson","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.rosehosting.com\/blog\/psql-connect-to-database-how-to-manage-postgresql-from-the-command-line\/#article","isPartOf":{"@id":"https:\/\/www.rosehosting.com\/blog\/psql-connect-to-database-how-to-manage-postgresql-from-the-command-line\/"},"author":{"name":"Jeff Wilson","@id":"https:\/\/www.rosehosting.com\/blog\/#\/schema\/person\/7ce77a842fa6a9a7f8efa186f2353713"},"headline":"PSQL Connect to Database: How to Manage PostgreSQL from the Command Line","datePublished":"2024-09-23T17:30:00+00:00","mainEntityOfPage":{"@id":"https:\/\/www.rosehosting.com\/blog\/psql-connect-to-database-how-to-manage-postgresql-from-the-command-line\/"},"wordCount":1372,"commentCount":0,"publisher":{"@id":"https:\/\/www.rosehosting.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.rosehosting.com\/blog\/psql-connect-to-database-how-to-manage-postgresql-from-the-command-line\/#primaryimage"},"thumbnailUrl":"https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2024\/09\/PSQL-Connect-to-Database-How-to-manage-PostgreSQL-from-the-command-line.webp","keywords":["database","how to","PostgreSQL","psql"],"articleSection":["Databases"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.rosehosting.com\/blog\/psql-connect-to-database-how-to-manage-postgresql-from-the-command-line\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.rosehosting.com\/blog\/psql-connect-to-database-how-to-manage-postgresql-from-the-command-line\/","url":"https:\/\/www.rosehosting.com\/blog\/psql-connect-to-database-how-to-manage-postgresql-from-the-command-line\/","name":"PSQL Connect to Database: Managing PostgreSQL | RoseHosting","isPartOf":{"@id":"https:\/\/www.rosehosting.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.rosehosting.com\/blog\/psql-connect-to-database-how-to-manage-postgresql-from-the-command-line\/#primaryimage"},"image":{"@id":"https:\/\/www.rosehosting.com\/blog\/psql-connect-to-database-how-to-manage-postgresql-from-the-command-line\/#primaryimage"},"thumbnailUrl":"https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2024\/09\/PSQL-Connect-to-Database-How-to-manage-PostgreSQL-from-the-command-line.webp","datePublished":"2024-09-23T17:30:00+00:00","description":"What is PSQL Connect to Database? Learn how to manage PostgreSQL from the command line using our latest step-by-step guide.","breadcrumb":{"@id":"https:\/\/www.rosehosting.com\/blog\/psql-connect-to-database-how-to-manage-postgresql-from-the-command-line\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.rosehosting.com\/blog\/psql-connect-to-database-how-to-manage-postgresql-from-the-command-line\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.rosehosting.com\/blog\/psql-connect-to-database-how-to-manage-postgresql-from-the-command-line\/#primaryimage","url":"https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2024\/09\/PSQL-Connect-to-Database-How-to-manage-PostgreSQL-from-the-command-line.webp","contentUrl":"https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2024\/09\/PSQL-Connect-to-Database-How-to-manage-PostgreSQL-from-the-command-line.webp","width":1024,"height":576,"caption":"How to Manage PostgreSQL from the command line with PSQL Connect to Database?"},{"@type":"BreadcrumbList","@id":"https:\/\/www.rosehosting.com\/blog\/psql-connect-to-database-how-to-manage-postgresql-from-the-command-line\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.rosehosting.com\/blog\/"},{"@type":"ListItem","position":2,"name":"PSQL Connect to Database: How to Manage PostgreSQL from the Command Line"}]},{"@type":"WebSite","@id":"https:\/\/www.rosehosting.com\/blog\/#website","url":"https:\/\/www.rosehosting.com\/blog\/","name":"RoseHosting.com","description":"Premium Linux Tutorials Since 2001","publisher":{"@id":"https:\/\/www.rosehosting.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.rosehosting.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.rosehosting.com\/blog\/#organization","name":"RoseHosting","url":"https:\/\/www.rosehosting.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.rosehosting.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2022\/03\/android-chrome-192x192-1.png","contentUrl":"https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2022\/03\/android-chrome-192x192-1.png","width":192,"height":192,"caption":"RoseHosting"},"image":{"@id":"https:\/\/www.rosehosting.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/RoseHosting","https:\/\/x.com\/rosehosting","https:\/\/www.linkedin.com\/in\/rosehosting\/"],"description":"RoseHosting is a leading Linux hosting provider, serving thousands of clients world-wide since 2001.","email":"info@rosehosting.com","telephone":"(314) 275-0414","legalName":"Rose Web Services LLC","foundingDate":"2001-04-02","numberOfEmployees":{"@type":"QuantitativeValue","minValue":"11","maxValue":"50"}},{"@type":"Person","@id":"https:\/\/www.rosehosting.com\/blog\/#\/schema\/person\/7ce77a842fa6a9a7f8efa186f2353713","name":"Jeff Wilson","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/0985fed6af04cc60703d2ecf27c65dfa373e0ca00eb21c0b03477e099ea3f99f?s=96&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/0985fed6af04cc60703d2ecf27c65dfa373e0ca00eb21c0b03477e099ea3f99f?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/0985fed6af04cc60703d2ecf27c65dfa373e0ca00eb21c0b03477e099ea3f99f?s=96&r=g","caption":"Jeff Wilson"},"description":"An experienced Linux veteran with many years of experience. Helping other Linux admins with frequent Linux and business-related blog posts on the RoseHosting blog. Techie by choice. Loving nature and travel. Happily married and father of two lovely children.","sameAs":["https:\/\/www.rosehosting.com","https:\/\/www.facebook.com\/rosehosting.helpdesk"],"url":"https:\/\/www.rosehosting.com\/blog\/author\/jwilson\/"}]}},"_links":{"self":[{"href":"https:\/\/www.rosehosting.com\/blog\/wp-json\/wp\/v2\/posts\/48892","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rosehosting.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rosehosting.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rosehosting.com\/blog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rosehosting.com\/blog\/wp-json\/wp\/v2\/comments?post=48892"}],"version-history":[{"count":8,"href":"https:\/\/www.rosehosting.com\/blog\/wp-json\/wp\/v2\/posts\/48892\/revisions"}],"predecessor-version":[{"id":49111,"href":"https:\/\/www.rosehosting.com\/blog\/wp-json\/wp\/v2\/posts\/48892\/revisions\/49111"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.rosehosting.com\/blog\/wp-json\/wp\/v2\/media\/49110"}],"wp:attachment":[{"href":"https:\/\/www.rosehosting.com\/blog\/wp-json\/wp\/v2\/media?parent=48892"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rosehosting.com\/blog\/wp-json\/wp\/v2\/categories?post=48892"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rosehosting.com\/blog\/wp-json\/wp\/v2\/tags?post=48892"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}