<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://tech.uvoo.io/index.php?action=history&amp;feed=atom&amp;title=Psql</id>
	<title>Psql - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://tech.uvoo.io/index.php?action=history&amp;feed=atom&amp;title=Psql"/>
	<link rel="alternate" type="text/html" href="https://tech.uvoo.io/index.php?title=Psql&amp;action=history"/>
	<updated>2026-05-17T06:27:52Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.35.2</generator>
	<entry>
		<id>https://tech.uvoo.io/index.php?title=Psql&amp;diff=3493&amp;oldid=prev</id>
		<title>Busk at 23:44, 7 October 2022</title>
		<link rel="alternate" type="text/html" href="https://tech.uvoo.io/index.php?title=Psql&amp;diff=3493&amp;oldid=prev"/>
		<updated>2022-10-07T23:44:43Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left diff-editfont-monospace&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 23:44, 7 October 2022&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l1&quot; &gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;```&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;psql postgresql://myrole:mypass@10.x.x.x:5432/zabbix?sslmode=disable&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;```&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;```&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;```&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;1) Connect to PostgreSQL database&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;1) Connect to PostgreSQL database&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Busk</name></author>
	</entry>
	<entry>
		<id>https://tech.uvoo.io/index.php?title=Psql&amp;diff=1118&amp;oldid=prev</id>
		<title>Busk: Created page with &quot;``` 1) Connect to PostgreSQL database The following command connects to a database under a specific user. After pressing Enter PostgreSQL will ask for the password of the user...&quot;</title>
		<link rel="alternate" type="text/html" href="https://tech.uvoo.io/index.php?title=Psql&amp;diff=1118&amp;oldid=prev"/>
		<updated>2021-01-17T02:10:35Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;``` 1) Connect to PostgreSQL database The following command connects to a database under a specific user. After pressing Enter PostgreSQL will ask for the password of the user...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;```&lt;br /&gt;
1) Connect to PostgreSQL database&lt;br /&gt;
The following command connects to a database under a specific user. After pressing Enter PostgreSQL will ask for the password of the user.&lt;br /&gt;
&lt;br /&gt;
psql -d database -U  user -W&lt;br /&gt;
Code language: SQL (Structured Query Language) (sql)&lt;br /&gt;
For example, to connect to dvdrental database under postgres user, you use the following command:&lt;br /&gt;
&lt;br /&gt;
C:\Program Files\PostgreSQL\9.5\bin&amp;gt;psql -d dvdrental -U postgres -W&lt;br /&gt;
Password for user postgres:&lt;br /&gt;
dvdrental=#&lt;br /&gt;
Code language: SQL (Structured Query Language) (sql)&lt;br /&gt;
If you want to connect to a database that resides on another host, you add the -h option as follows:&lt;br /&gt;
&lt;br /&gt;
psql -h host -d database -U user -W&lt;br /&gt;
Code language: SQL (Structured Query Language) (sql)&lt;br /&gt;
In case you want to use SSL mode for the connection, just specify it as shown in the following command:&lt;br /&gt;
&lt;br /&gt;
psql -U user -h host &amp;quot;dbname=db sslmode=require&amp;quot;&lt;br /&gt;
Code language: SQL (Structured Query Language) (sql)&lt;br /&gt;
2) Switch connection to a new database&lt;br /&gt;
Once you are connected to a database, you can switch the connection to a new database under a user specified by user. The previous connection will be closed. If you omit the user parameter, the current user is assumed.&lt;br /&gt;
&lt;br /&gt;
\c dbname username&lt;br /&gt;
The following command connects to dvdrental database under postgres user:&lt;br /&gt;
&lt;br /&gt;
postgres=# \c dvdrental&lt;br /&gt;
You are now connected to database &amp;quot;dvdrental&amp;quot; as user &amp;quot;postgres&amp;quot;.&lt;br /&gt;
dvdrental=#&lt;br /&gt;
Code language: PHP (php)&lt;br /&gt;
3) List available databases&lt;br /&gt;
To list all databases in the current PostgreSQL database server, you use \l command:&lt;br /&gt;
&lt;br /&gt;
\l&lt;br /&gt;
Code language: SQL (Structured Query Language) (sql)&lt;br /&gt;
4) List available tables&lt;br /&gt;
To list all tables in the current database, you use \dt command:&lt;br /&gt;
&lt;br /&gt;
\dt&lt;br /&gt;
Code language: SQL (Structured Query Language) (sql)&lt;br /&gt;
Note that this command shows the only table in the currently connected database.&lt;br /&gt;
&lt;br /&gt;
5) Describe a table&lt;br /&gt;
To describe a table such as a column, type, modifiers of columns, etc., you use the following command:&lt;br /&gt;
&lt;br /&gt;
\d table_name&lt;br /&gt;
Code language: SQL (Structured Query Language) (sql)&lt;br /&gt;
6) List available schema&lt;br /&gt;
To list all schemas of the currently connected database, you use the \dn command.&lt;br /&gt;
&lt;br /&gt;
\dn&lt;br /&gt;
Code language: SQL (Structured Query Language) (sql)&lt;br /&gt;
7) List available functions&lt;br /&gt;
To list available functions in the current database, you use the \df command.&lt;br /&gt;
&lt;br /&gt;
\df&lt;br /&gt;
Code language: SQL (Structured Query Language) (sql)&lt;br /&gt;
8) List available views&lt;br /&gt;
To list available views in the current database, you use the \dv command.&lt;br /&gt;
&lt;br /&gt;
\dv&lt;br /&gt;
Code language: SQL (Structured Query Language) (sql)&lt;br /&gt;
9) List users and their roles&lt;br /&gt;
To list all users and their assign roles, you use \du command:&lt;br /&gt;
&lt;br /&gt;
\du&lt;br /&gt;
Code language: SQL (Structured Query Language) (sql)&lt;br /&gt;
10) Execute the previous command&lt;br /&gt;
To retrieve the current version of PostgreSQL server, you use the version() function as follows:&lt;br /&gt;
&lt;br /&gt;
SELECT version();&lt;br /&gt;
Code language: SQL (Structured Query Language) (sql)&lt;br /&gt;
Now, you want to save time typing the previous command again, you can use \g command to execute the previous command:&lt;br /&gt;
&lt;br /&gt;
\g&lt;br /&gt;
Code language: SQL (Structured Query Language) (sql)&lt;br /&gt;
psql executes the previous command again, which is the SELECT statement,.&lt;br /&gt;
&lt;br /&gt;
11) Command history&lt;br /&gt;
To display command history, you use the \s command.&lt;br /&gt;
&lt;br /&gt;
\s&lt;br /&gt;
Code language: SQL (Structured Query Language) (sql)&lt;br /&gt;
If you want to save the command history to a file, you need to specify the file name followed the \s command as follows:&lt;br /&gt;
&lt;br /&gt;
\s filename&lt;br /&gt;
Code language: SQL (Structured Query Language) (sql)&lt;br /&gt;
12) Execute psql commands from a file&lt;br /&gt;
In case you want to execute psql commands from a file, you use \i command as follows:&lt;br /&gt;
&lt;br /&gt;
\i filename&lt;br /&gt;
Code language: SQL (Structured Query Language) (sql)&lt;br /&gt;
13) Get help on psql commands&lt;br /&gt;
To know all available psql commands, you use the \? command.&lt;br /&gt;
&lt;br /&gt;
\?&lt;br /&gt;
Code language: SQL (Structured Query Language) (sql)&lt;br /&gt;
To get help on specific PostgreSQL statement, you use the \h command.&lt;br /&gt;
&lt;br /&gt;
For example, if you want to know detailed information on ALTER TABLE statement, you use the following command:&lt;br /&gt;
&lt;br /&gt;
\h ALTER TABLE&lt;br /&gt;
Code language: SQL (Structured Query Language) (sql)&lt;br /&gt;
14) Turn on query execution time&lt;br /&gt;
To turn on query execution time, you use the \timing command.&lt;br /&gt;
&lt;br /&gt;
dvdrental=# \timing&lt;br /&gt;
Timing is on.&lt;br /&gt;
dvdrental=# select count(*) from film;&lt;br /&gt;
 count&lt;br /&gt;
-------&lt;br /&gt;
  1000&lt;br /&gt;
(1 row)&lt;br /&gt;
&lt;br /&gt;
Time: 1.495 ms&lt;br /&gt;
dvdrental=#&lt;br /&gt;
Code language: SQL (Structured Query Language) (sql)&lt;br /&gt;
You use the same command \timing to turn it off.&lt;br /&gt;
&lt;br /&gt;
dvdrental=# \timing&lt;br /&gt;
Timing is off.&lt;br /&gt;
dvdrental=#&lt;br /&gt;
```&lt;/div&gt;</summary>
		<author><name>Busk</name></author>
	</entry>
</feed>