<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>psql &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/tag/psql/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.dbrnd.com</link>
	<description>BIGData &#124; NoSQL &#124; MSSQL &#124; MySQL &#124; PostgreSQL</description>
	<lastBuildDate>Mon, 21 Jan 2019 07:18:49 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0.4</generator>
	<item>
		<title>PostgreSQL: Bash Shell Script to execute psql command in UNIX / LINUX</title>
		<link>https://www.dbrnd.com/2019/03/postgresql-bash-shell-script-to-execute-psql-command-in-unix-linux/</link>
					<comments>https://www.dbrnd.com/2019/03/postgresql-bash-shell-script-to-execute-psql-command-in-unix-linux/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Mon, 04 Mar 2019 16:16:25 +0000</pubDate>
				<category><![CDATA[Bash Shell Script]]></category>
		<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[PostgreSQL DBA Script]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[Bash shell script]]></category>
		<category><![CDATA[chmod]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[plpgsql]]></category>
		<category><![CDATA[Postgres Query]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[PostgreSQL Administrator]]></category>
		<category><![CDATA[PostgreSQL Error]]></category>
		<category><![CDATA[PostgreSQL Monitoring]]></category>
		<category><![CDATA[PostgreSQL Performance Tuning]]></category>
		<category><![CDATA[PostgreSQL Programming]]></category>
		<category><![CDATA[PostgreSQL Tips and Tricks]]></category>
		<category><![CDATA[psql]]></category>
		<category><![CDATA[vi editor]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=4374</guid>

					<description><![CDATA[As per the en.wikibooks.org: Bash is a &#8220;Unix shell&#8221;: a command-line interface for interacting with the operating system. It has the ability to run an entire script of commands, known as a &#8220;Bash shell script&#8221;. I recently started to create UNIX / LINUX Bash Shell script for enhancing my PostgreSQL DBA Work. You can create [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2019%2F03%2Fpostgresql-bash-shell-script-to-execute-psql-command-in-unix-linux%2F&amp;linkname=PostgreSQL%3A%20Bash%20Shell%20Script%20to%20execute%20psql%20command%20in%20UNIX%20%2F%20LINUX" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2019%2F03%2Fpostgresql-bash-shell-script-to-execute-psql-command-in-unix-linux%2F&amp;linkname=PostgreSQL%3A%20Bash%20Shell%20Script%20to%20execute%20psql%20command%20in%20UNIX%20%2F%20LINUX" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2019%2F03%2Fpostgresql-bash-shell-script-to-execute-psql-command-in-unix-linux%2F&amp;linkname=PostgreSQL%3A%20Bash%20Shell%20Script%20to%20execute%20psql%20command%20in%20UNIX%20%2F%20LINUX" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2019%2F03%2Fpostgresql-bash-shell-script-to-execute-psql-command-in-unix-linux%2F&amp;linkname=PostgreSQL%3A%20Bash%20Shell%20Script%20to%20execute%20psql%20command%20in%20UNIX%20%2F%20LINUX" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2019%2F03%2Fpostgresql-bash-shell-script-to-execute-psql-command-in-unix-linux%2F&amp;linkname=PostgreSQL%3A%20Bash%20Shell%20Script%20to%20execute%20psql%20command%20in%20UNIX%20%2F%20LINUX" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2019%2F03%2Fpostgresql-bash-shell-script-to-execute-psql-command-in-unix-linux%2F&amp;linkname=PostgreSQL%3A%20Bash%20Shell%20Script%20to%20execute%20psql%20command%20in%20UNIX%20%2F%20LINUX" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2019%2F03%2Fpostgresql-bash-shell-script-to-execute-psql-command-in-unix-linux%2F&#038;title=PostgreSQL%3A%20Bash%20Shell%20Script%20to%20execute%20psql%20command%20in%20UNIX%20%2F%20LINUX" data-a2a-url="https://www.dbrnd.com/2019/03/postgresql-bash-shell-script-to-execute-psql-command-in-unix-linux/" data-a2a-title="PostgreSQL: Bash Shell Script to execute psql command in UNIX / LINUX"></a></p><p>As per the en.wikibooks.org:</p>
<blockquote><p>Bash is a &#8220;Unix shell&#8221;: a command-line interface for interacting with the operating system. It has the ability to run an entire script of commands, known as a &#8220;Bash shell script&#8221;.</p></blockquote>
<p>I recently started to create UNIX / LINUX Bash Shell script for enhancing my PostgreSQL DBA Work. You can create a Bash shell script and can connect PostgreSQL using psql. </p>
<p>In this post, I am sharing a sample bash shell script to execute psql commands. </p>
<p><strong>Open a new file in vi editor:</strong></p>
<pre class="crayon-plain-tag">[root@dbrnd anvesh]$ vi helloworld.bash</pre> </p>
<p><strong>Press [i] key to get an insert prompt:</strong></p>
<p><strong>Copy below sample Bash Shell Script and Paste into vi editor:</strong></p>
<pre class="crayon-plain-tag">#!/bin/bash

###################################################
# First Bash Shell script to execute psql command 
###################################################

#Set the value of variable
database="database_name"

#Execute few psql commands: 
#Note: you can also add -h hostname -U username in the below commands. 

psql -d $database -c "CREATE TABLE public.tbl_students(rno integer, name character varying)"
psql -d $database -c "INSERT INTO public.tbl_students VALUES (1,'Anvesh'),(2,'Neevan'),(3,'Roy'),(4,'Martin'),(5,'Jenny')"
psql -d $database -c "SELECT *FROM public.tbl_students"

#Assign table count to variable
TableCount=$(psql -d $database -t -c "select count(1) from public.tbl_students")

#Print the value of variable
echo "Total table records count....:"$TableCount</pre> </p>
<p><strong>Press [Esc] key to get a command prompt and execute below command:</strong><br />
To save and exit vi editor.</p>
<pre class="crayon-plain-tag">:wq</pre> </p>
<p><strong>Give permission to the file:</strong></p>
<pre class="crayon-plain-tag">[root@dbrnd anvesh]$ chmod +x helloworld.bash</pre> </p>
<p><strong>Execute this file:</strong></p>
<pre class="crayon-plain-tag">[root@dbrnd anvesh]$ ./helloworld.bash</pre> </p>
<p><strong>You can find below result:</strong></p>
<pre class="crayon-plain-tag">rno |  name
-----+--------
   1 | Anvesh
   5 | Jenny
   2 | Neevan
   3 | Roy
   4 | Martin
(5 rows)

Total table records count....: 5</pre> </p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2019/03/postgresql-bash-shell-script-to-execute-psql-command-in-unix-linux/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>PostgreSQL: How to get the list of all Schemas of a database in PSQL?</title>
		<link>https://www.dbrnd.com/2018/08/postgresql-how-to-get-the-list-of-all-schemas-of-a-database-in-psql/</link>
					<comments>https://www.dbrnd.com/2018/08/postgresql-how-to-get-the-list-of-all-schemas-of-a-database-in-psql/#respond</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Mon, 27 Aug 2018 16:16:27 +0000</pubDate>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[PostgreSQL DBA Script]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[Get schemas]]></category>
		<category><![CDATA[plpgsql]]></category>
		<category><![CDATA[Postgres Query]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[PostgreSQL Administrator]]></category>
		<category><![CDATA[PostgreSQL Error]]></category>
		<category><![CDATA[PostgreSQL Monitoring]]></category>
		<category><![CDATA[PostgreSQL Performance Tuning]]></category>
		<category><![CDATA[PostgreSQL Programming]]></category>
		<category><![CDATA[PostgreSQL Tips and Tricks]]></category>
		<category><![CDATA[psql]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=7705</guid>

					<description><![CDATA[In this post, I am sharing a command of PSQL for getting the list of Schemas of a database in PostgreSQL. PSQL is a handy tool for PostgreSQL DBAs and they are always preferring to use a command line tool. This article is for PostgreSQL beginner who is looking for the list of Schemas in [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F08%2Fpostgresql-how-to-get-the-list-of-all-schemas-of-a-database-in-psql%2F&amp;linkname=PostgreSQL%3A%20How%20to%20get%20the%20list%20of%20all%20Schemas%20of%20a%20database%20in%20PSQL%3F" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F08%2Fpostgresql-how-to-get-the-list-of-all-schemas-of-a-database-in-psql%2F&amp;linkname=PostgreSQL%3A%20How%20to%20get%20the%20list%20of%20all%20Schemas%20of%20a%20database%20in%20PSQL%3F" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F08%2Fpostgresql-how-to-get-the-list-of-all-schemas-of-a-database-in-psql%2F&amp;linkname=PostgreSQL%3A%20How%20to%20get%20the%20list%20of%20all%20Schemas%20of%20a%20database%20in%20PSQL%3F" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F08%2Fpostgresql-how-to-get-the-list-of-all-schemas-of-a-database-in-psql%2F&amp;linkname=PostgreSQL%3A%20How%20to%20get%20the%20list%20of%20all%20Schemas%20of%20a%20database%20in%20PSQL%3F" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F08%2Fpostgresql-how-to-get-the-list-of-all-schemas-of-a-database-in-psql%2F&amp;linkname=PostgreSQL%3A%20How%20to%20get%20the%20list%20of%20all%20Schemas%20of%20a%20database%20in%20PSQL%3F" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F08%2Fpostgresql-how-to-get-the-list-of-all-schemas-of-a-database-in-psql%2F&amp;linkname=PostgreSQL%3A%20How%20to%20get%20the%20list%20of%20all%20Schemas%20of%20a%20database%20in%20PSQL%3F" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F08%2Fpostgresql-how-to-get-the-list-of-all-schemas-of-a-database-in-psql%2F&#038;title=PostgreSQL%3A%20How%20to%20get%20the%20list%20of%20all%20Schemas%20of%20a%20database%20in%20PSQL%3F" data-a2a-url="https://www.dbrnd.com/2018/08/postgresql-how-to-get-the-list-of-all-schemas-of-a-database-in-psql/" data-a2a-title="PostgreSQL: How to get the list of all Schemas of a database in PSQL?"></a></p><p>In this post, I am sharing a command of PSQL for getting the list of Schemas of a database in PostgreSQL.</p>
<p>PSQL is a handy tool for PostgreSQL DBAs and they are always preferring to use a command line tool. </p>
<p>This article is for PostgreSQL beginner who is looking for the list of Schemas in PostgreSQL.</p>
<p><strong>How to connect the database in PSQL?</strong></p>
<pre class="crayon-plain-tag">-psql&gt;\connect database_name</pre> </p>
<p><strong>Get the list of schemas:</strong></p>
<pre class="crayon-plain-tag">-psql&gt; \dn</pre> </p>
<p><strong>Get the list of databases:</strong></p>
<pre class="crayon-plain-tag">-psql&gt; \list 
or 
-psql&gt; \l</pre> </p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2018/08/postgresql-how-to-get-the-list-of-all-schemas-of-a-database-in-psql/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>PostgreSQL: How to get the list of all privileges of a database in PSQL?</title>
		<link>https://www.dbrnd.com/2018/08/postgresql-how-to-get-the-list-of-all-privileges-of-a-database-in-psql/</link>
					<comments>https://www.dbrnd.com/2018/08/postgresql-how-to-get-the-list-of-all-privileges-of-a-database-in-psql/#respond</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Mon, 20 Aug 2018 16:16:26 +0000</pubDate>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[PostgreSQL DBA Script]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[get databases]]></category>
		<category><![CDATA[get privileges]]></category>
		<category><![CDATA[plpgsql]]></category>
		<category><![CDATA[Postgres Query]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[PostgreSQL Administrator]]></category>
		<category><![CDATA[PostgreSQL Error]]></category>
		<category><![CDATA[PostgreSQL Monitoring]]></category>
		<category><![CDATA[PostgreSQL Performance Tuning]]></category>
		<category><![CDATA[PostgreSQL Programming]]></category>
		<category><![CDATA[PostgreSQL Tips and Tricks]]></category>
		<category><![CDATA[psql]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=7703</guid>

					<description><![CDATA[In this post, I am sharing a command of PSQL for getting the list of privileges of a database in PostgreSQL. PSQL is a handy tool for PostgreSQL DBAs and they are always preferring to use a command line tool. This article is for PostgreSQL beginner who is looking for the list of privileges in [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F08%2Fpostgresql-how-to-get-the-list-of-all-privileges-of-a-database-in-psql%2F&amp;linkname=PostgreSQL%3A%20How%20to%20get%20the%20list%20of%20all%20privileges%20of%20a%20database%20in%20PSQL%3F" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F08%2Fpostgresql-how-to-get-the-list-of-all-privileges-of-a-database-in-psql%2F&amp;linkname=PostgreSQL%3A%20How%20to%20get%20the%20list%20of%20all%20privileges%20of%20a%20database%20in%20PSQL%3F" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F08%2Fpostgresql-how-to-get-the-list-of-all-privileges-of-a-database-in-psql%2F&amp;linkname=PostgreSQL%3A%20How%20to%20get%20the%20list%20of%20all%20privileges%20of%20a%20database%20in%20PSQL%3F" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F08%2Fpostgresql-how-to-get-the-list-of-all-privileges-of-a-database-in-psql%2F&amp;linkname=PostgreSQL%3A%20How%20to%20get%20the%20list%20of%20all%20privileges%20of%20a%20database%20in%20PSQL%3F" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F08%2Fpostgresql-how-to-get-the-list-of-all-privileges-of-a-database-in-psql%2F&amp;linkname=PostgreSQL%3A%20How%20to%20get%20the%20list%20of%20all%20privileges%20of%20a%20database%20in%20PSQL%3F" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F08%2Fpostgresql-how-to-get-the-list-of-all-privileges-of-a-database-in-psql%2F&amp;linkname=PostgreSQL%3A%20How%20to%20get%20the%20list%20of%20all%20privileges%20of%20a%20database%20in%20PSQL%3F" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F08%2Fpostgresql-how-to-get-the-list-of-all-privileges-of-a-database-in-psql%2F&#038;title=PostgreSQL%3A%20How%20to%20get%20the%20list%20of%20all%20privileges%20of%20a%20database%20in%20PSQL%3F" data-a2a-url="https://www.dbrnd.com/2018/08/postgresql-how-to-get-the-list-of-all-privileges-of-a-database-in-psql/" data-a2a-title="PostgreSQL: How to get the list of all privileges of a database in PSQL?"></a></p><p>In this post, I am sharing a command of PSQL for getting the list of privileges of a database in PostgreSQL.</p>
<p>PSQL is a handy tool for PostgreSQL DBAs and they are always preferring to use a command line tool. </p>
<p>This article is for PostgreSQL beginner who is looking for the list of privileges in PostgreSQL.</p>
<p><strong>How to connect the database in PSQL?</strong></p>
<pre class="crayon-plain-tag">-psql&gt;\connect database_name</pre> </p>
<p><strong>Get the list of databases:</strong></p>
<pre class="crayon-plain-tag">-psql&gt; \list 
or 
-psql&gt; \l</pre> </p>
<p><strong>Get the list of privileges:</strong></p>
<pre class="crayon-plain-tag">-psql&gt; \du</pre> </p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2018/08/postgresql-how-to-get-the-list-of-all-privileges-of-a-database-in-psql/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>PostgreSQL: How to get the list of all tables and all databases in PSQL?</title>
		<link>https://www.dbrnd.com/2018/08/postgresql-how-to-get-the-list-of-all-tables-and-all-databases-in-psql/</link>
					<comments>https://www.dbrnd.com/2018/08/postgresql-how-to-get-the-list-of-all-tables-and-all-databases-in-psql/#respond</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Mon, 13 Aug 2018 16:16:20 +0000</pubDate>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[PostgreSQL DBA Script]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[get databases]]></category>
		<category><![CDATA[get tables]]></category>
		<category><![CDATA[plpgsql]]></category>
		<category><![CDATA[Postgres Query]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[PostgreSQL Administrator]]></category>
		<category><![CDATA[PostgreSQL Error]]></category>
		<category><![CDATA[PostgreSQL Monitoring]]></category>
		<category><![CDATA[PostgreSQL Performance Tuning]]></category>
		<category><![CDATA[PostgreSQL Programming]]></category>
		<category><![CDATA[PostgreSQL Tips and Tricks]]></category>
		<category><![CDATA[psql]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=7700</guid>

					<description><![CDATA[In this post, I am sharing two commands of PSQL for getting the list of tables and databases in PostgreSQL. PSQL is a handy tool for PostgreSQL DBAs and they are always preferring to use a command line tool. This article is for PostgreSQL beginner who is looking for the list of tables and databases [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F08%2Fpostgresql-how-to-get-the-list-of-all-tables-and-all-databases-in-psql%2F&amp;linkname=PostgreSQL%3A%20How%20to%20get%20the%20list%20of%20all%20tables%20and%20all%20databases%20in%20PSQL%3F" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F08%2Fpostgresql-how-to-get-the-list-of-all-tables-and-all-databases-in-psql%2F&amp;linkname=PostgreSQL%3A%20How%20to%20get%20the%20list%20of%20all%20tables%20and%20all%20databases%20in%20PSQL%3F" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F08%2Fpostgresql-how-to-get-the-list-of-all-tables-and-all-databases-in-psql%2F&amp;linkname=PostgreSQL%3A%20How%20to%20get%20the%20list%20of%20all%20tables%20and%20all%20databases%20in%20PSQL%3F" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F08%2Fpostgresql-how-to-get-the-list-of-all-tables-and-all-databases-in-psql%2F&amp;linkname=PostgreSQL%3A%20How%20to%20get%20the%20list%20of%20all%20tables%20and%20all%20databases%20in%20PSQL%3F" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F08%2Fpostgresql-how-to-get-the-list-of-all-tables-and-all-databases-in-psql%2F&amp;linkname=PostgreSQL%3A%20How%20to%20get%20the%20list%20of%20all%20tables%20and%20all%20databases%20in%20PSQL%3F" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F08%2Fpostgresql-how-to-get-the-list-of-all-tables-and-all-databases-in-psql%2F&amp;linkname=PostgreSQL%3A%20How%20to%20get%20the%20list%20of%20all%20tables%20and%20all%20databases%20in%20PSQL%3F" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F08%2Fpostgresql-how-to-get-the-list-of-all-tables-and-all-databases-in-psql%2F&#038;title=PostgreSQL%3A%20How%20to%20get%20the%20list%20of%20all%20tables%20and%20all%20databases%20in%20PSQL%3F" data-a2a-url="https://www.dbrnd.com/2018/08/postgresql-how-to-get-the-list-of-all-tables-and-all-databases-in-psql/" data-a2a-title="PostgreSQL: How to get the list of all tables and all databases in PSQL?"></a></p><p>In this post, I am sharing two commands of PSQL for getting the list of tables and databases in PostgreSQL.</p>
<p>PSQL is a handy tool for PostgreSQL DBAs and they are always preferring to use a command line tool. </p>
<p>This article is for PostgreSQL beginner who is looking for the list of tables and databases in PostgreSQL.</p>
<p><strong>Get the list of databases:</strong></p>
<pre class="crayon-plain-tag">-psql&gt; \list 
or 
-psql&gt; \l</pre> </p>
<p><strong>Get the list of tables:</strong><br />
You can&#8217;t get the list of all tables of all databases, but you can get the list of all tables of a particular database.<br />
First, you need to connect the database and then execute below command.</p>
<pre class="crayon-plain-tag">-psql&gt; \dt</pre> </p>
<p><strong>How to connect the database in PSQL?</strong></p>
<pre class="crayon-plain-tag">-psql&gt;\connect database_name</pre> </p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2018/08/postgresql-how-to-get-the-list-of-all-tables-and-all-databases-in-psql/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>PostgreSQL: Use PSQL command line variable to make your SQL Queries Dynamic</title>
		<link>https://www.dbrnd.com/2017/06/postgresql-use-psql-command-line-variable-to-make-your-sql-queries-dynamic/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Mon, 19 Jun 2017 16:16:53 +0000</pubDate>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[plpgsql]]></category>
		<category><![CDATA[Postgres Query]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[PostgreSQL Administrator]]></category>
		<category><![CDATA[PostgreSQL Error]]></category>
		<category><![CDATA[PostgreSQL Monitoring]]></category>
		<category><![CDATA[PostgreSQL Performance Tuning]]></category>
		<category><![CDATA[PostgreSQL Programming]]></category>
		<category><![CDATA[PostgreSQL Tips and Tricks]]></category>
		<category><![CDATA[psql]]></category>
		<category><![CDATA[session variable]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=5428</guid>

					<description><![CDATA[In this post, I am sharing tips like how to use a psql session variable to make your queries more dynamic in PostgreSQL. As a DBA, we prepared lots of .sql files in our server for different purposes like check DB stats, get tables size, get object information. We are executing this scripts (.sql files) [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F06%2Fpostgresql-use-psql-command-line-variable-to-make-your-sql-queries-dynamic%2F&amp;linkname=PostgreSQL%3A%20Use%20PSQL%20command%20line%20variable%20to%20make%20your%20SQL%20Queries%20Dynamic" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F06%2Fpostgresql-use-psql-command-line-variable-to-make-your-sql-queries-dynamic%2F&amp;linkname=PostgreSQL%3A%20Use%20PSQL%20command%20line%20variable%20to%20make%20your%20SQL%20Queries%20Dynamic" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F06%2Fpostgresql-use-psql-command-line-variable-to-make-your-sql-queries-dynamic%2F&amp;linkname=PostgreSQL%3A%20Use%20PSQL%20command%20line%20variable%20to%20make%20your%20SQL%20Queries%20Dynamic" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F06%2Fpostgresql-use-psql-command-line-variable-to-make-your-sql-queries-dynamic%2F&amp;linkname=PostgreSQL%3A%20Use%20PSQL%20command%20line%20variable%20to%20make%20your%20SQL%20Queries%20Dynamic" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F06%2Fpostgresql-use-psql-command-line-variable-to-make-your-sql-queries-dynamic%2F&amp;linkname=PostgreSQL%3A%20Use%20PSQL%20command%20line%20variable%20to%20make%20your%20SQL%20Queries%20Dynamic" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F06%2Fpostgresql-use-psql-command-line-variable-to-make-your-sql-queries-dynamic%2F&amp;linkname=PostgreSQL%3A%20Use%20PSQL%20command%20line%20variable%20to%20make%20your%20SQL%20Queries%20Dynamic" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F06%2Fpostgresql-use-psql-command-line-variable-to-make-your-sql-queries-dynamic%2F&#038;title=PostgreSQL%3A%20Use%20PSQL%20command%20line%20variable%20to%20make%20your%20SQL%20Queries%20Dynamic" data-a2a-url="https://www.dbrnd.com/2017/06/postgresql-use-psql-command-line-variable-to-make-your-sql-queries-dynamic/" data-a2a-title="PostgreSQL: Use PSQL command line variable to make your SQL Queries Dynamic"></a></p><p>In this post, I am sharing tips like how to use a psql session variable to make your queries more dynamic in PostgreSQL.</p>
<p>As a DBA, we prepared lots of .sql files in our server for different purposes like check DB stats, get tables size, get object information.</p>
<blockquote><p>We are executing this scripts (.sql files) many times, but every time we have to change the schema name parameters because we are checking for different schemas and we hard coded the schema values in the SQL scripts.</p>
<p>I found one solution to resolve this problem, that is PSQL Command line variable. You can declare the variable in the PSQL Session and can use for that session.</p></blockquote>
<p>The benefit of this is, you do not require to update .sql files for again and again, and multiple people can use same SQL script at a time for different schemas.</p>
<p><em>Note: As this is a session variable so whenever you connect to PSQL, you have to declare this variable.</em></p>
<p><strong>Check the below demonstration:</strong></p>
<p><strong>Step 1: Connect to PSQL</strong></p>
<pre class="crayon-plain-tag">root-&gt; psql -d database_name</pre> </p>
<p><strong>Step 2: Create a session variable</strong></p>
<pre class="crayon-plain-tag">psql-&gt; \set SchemaVariable '\'my_schema_1\''</pre> </p>
<p><strong>Step 3: Embed that variable in your SELECT script of .sql file</strong></p>
<pre class="crayon-plain-tag">select       
       tablename
       ,attname      
       ,avg_width
from pg_stats
where schemaname = :SchemaVariable;</pre> </p>
<p>If you are using a list of schemas, you can also assign multiple schema names to a session variable.</p>
<p><strong>Declare session variable for multiple values:</strong></p>
<pre class="crayon-plain-tag">\set SchemaVariable '\'my_schema_1\',\'my_schema_2\''</pre> </p>
<p><strong>Use session variable in IN clause:</strong></p>
<pre class="crayon-plain-tag">select       
       tablename
       ,attname      
       ,avg_width
from pg_stats
where schemaname in (:SchemaVariable);</pre> </p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>PostgreSQL: Use pg_dump &#124; SSH &#124; psql, Copy Table data from a Server to another Server</title>
		<link>https://www.dbrnd.com/2017/04/postgresql-use-pg_dump-ssh-psql-copy-table-data-from-a-server-to-another-server/</link>
					<comments>https://www.dbrnd.com/2017/04/postgresql-use-pg_dump-ssh-psql-copy-table-data-from-a-server-to-another-server/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Mon, 24 Apr 2017 16:16:47 +0000</pubDate>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[Migrate table data]]></category>
		<category><![CDATA[pg_dump]]></category>
		<category><![CDATA[plpgsql]]></category>
		<category><![CDATA[Postgres Query]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[PostgreSQL Administrator]]></category>
		<category><![CDATA[PostgreSQL Error]]></category>
		<category><![CDATA[PostgreSQL Monitoring]]></category>
		<category><![CDATA[PostgreSQL Performance Tuning]]></category>
		<category><![CDATA[PostgreSQL Programming]]></category>
		<category><![CDATA[PostgreSQL Tips and Tricks]]></category>
		<category><![CDATA[psql]]></category>
		<category><![CDATA[SSH]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=5065</guid>

					<description><![CDATA[The migration of data and tables between the server are a very common task for Database Administrator. In this post, I am sharing few options to migrate your data between servers such a way that you do not require to create any additional table backup file. Using pg_dump, SSH and PSQL, you can directly copy [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F04%2Fpostgresql-use-pg_dump-ssh-psql-copy-table-data-from-a-server-to-another-server%2F&amp;linkname=PostgreSQL%3A%20Use%20pg_dump%20%7C%20SSH%20%7C%20psql%2C%20Copy%20Table%20data%20from%20a%20Server%20to%20another%20Server" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F04%2Fpostgresql-use-pg_dump-ssh-psql-copy-table-data-from-a-server-to-another-server%2F&amp;linkname=PostgreSQL%3A%20Use%20pg_dump%20%7C%20SSH%20%7C%20psql%2C%20Copy%20Table%20data%20from%20a%20Server%20to%20another%20Server" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F04%2Fpostgresql-use-pg_dump-ssh-psql-copy-table-data-from-a-server-to-another-server%2F&amp;linkname=PostgreSQL%3A%20Use%20pg_dump%20%7C%20SSH%20%7C%20psql%2C%20Copy%20Table%20data%20from%20a%20Server%20to%20another%20Server" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F04%2Fpostgresql-use-pg_dump-ssh-psql-copy-table-data-from-a-server-to-another-server%2F&amp;linkname=PostgreSQL%3A%20Use%20pg_dump%20%7C%20SSH%20%7C%20psql%2C%20Copy%20Table%20data%20from%20a%20Server%20to%20another%20Server" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F04%2Fpostgresql-use-pg_dump-ssh-psql-copy-table-data-from-a-server-to-another-server%2F&amp;linkname=PostgreSQL%3A%20Use%20pg_dump%20%7C%20SSH%20%7C%20psql%2C%20Copy%20Table%20data%20from%20a%20Server%20to%20another%20Server" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F04%2Fpostgresql-use-pg_dump-ssh-psql-copy-table-data-from-a-server-to-another-server%2F&amp;linkname=PostgreSQL%3A%20Use%20pg_dump%20%7C%20SSH%20%7C%20psql%2C%20Copy%20Table%20data%20from%20a%20Server%20to%20another%20Server" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F04%2Fpostgresql-use-pg_dump-ssh-psql-copy-table-data-from-a-server-to-another-server%2F&#038;title=PostgreSQL%3A%20Use%20pg_dump%20%7C%20SSH%20%7C%20psql%2C%20Copy%20Table%20data%20from%20a%20Server%20to%20another%20Server" data-a2a-url="https://www.dbrnd.com/2017/04/postgresql-use-pg_dump-ssh-psql-copy-table-data-from-a-server-to-another-server/" data-a2a-title="PostgreSQL: Use pg_dump | SSH | psql, Copy Table data from a Server to another Server"></a></p><p>The migration of data and tables between the server are a very common task for Database Administrator.</p>
<p>In this post, I am sharing few options to migrate your data between servers such a way that you do not require to create any additional table backup file.</p>
<p>Using pg_dump, SSH and PSQL, you can directly copy your table data from one server to another server.</p>
<blockquote><p>Recently, I had taken PostgreSQL DBA interview and asked question like &#8220;How to migrate table data from one server to another in PostgreSQL?&#8221;</p>
<p>A candidate said, create table backup file using pg_dump -&gt; copy that file in source server -&gt; use pg_restore to restore it.<br />
Don&#8217;t you think, so that above process is very long? Check the below few options, and you can migrate your data without any table backup file.</p></blockquote>
<p><strong>My Destination information:</strong></p>
<ul>
<li>Host: pgtest1.dbrnd.com</li>
<li>Table: public.tbl_stud</li>
<li>User: anvesh</li>
<li>Database: Students</li>
</ul>
<p><strong>My Source information:</strong></p>
<ul>
<li>Host: pgtest2.dbrnd.com</li>
<li>Table: public.tbl_stud</li>
<li>User: anvesh</li>
<li>Database: Students_test</li>
</ul>
<p><strong>Important Note:</strong></p>
<blockquote><p>Both the side table structure must be same like number columns and datatype of a column.</p></blockquote>
<p><strong>Option #1: Using SSH | PSQL</strong><br />
Use pg_dump with SSH | PSQL, and execute below command. It will ask password for pgtest2.dbrnd.com, and I set database password using variable PGPASSWORD. It will migrate only table data between server.</p><pre class="crayon-plain-tag">pg_dump --data-only --table=public.tbl_stud Students | ssh anvesh@pgtest2.dbrnd.com "PGPASSWORD=mypass psql -h pgtest2.dbrnd.com -U anvesh Students_test"</pre><p>
<strong>Option #2: Using only PSQL (Transfer data only)</strong><br />
Option -a is for data only.</p><pre class="crayon-plain-tag">pg_dump -t public.tbl_stud -a Students | psql -h pgtest2.dbrnd.com -p 5432 -d Students_test</pre><p>
<strong>Option #3: Using only PSQL (Transfer table structure with data)</strong></p><pre class="crayon-plain-tag">pg_dump -t public.tbl_stud Students | psql -h pgtest2.dbrnd.com -p 5432 -d Students_test</pre><p>
<strong>You can access below other related articles:</strong></p>
<ul>
<li><a href="https://www.dbrnd.com/2017/02/postgresql-how-to-take-a-backup-of-your-table-pg_dump-pg_admin/" target="_blank">Take a backup of your table:</a></li>
<li><a href="https://www.dbrnd.com/2017/02/postgresql-script-to-copy-schema-table-data-to-another-schema-table-migration/" target="_blank">Copy data between your schemas:</a></li>
</ul>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2017/04/postgresql-use-pg_dump-ssh-psql-copy-table-data-from-a-server-to-another-server/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>PostgreSQL 9.6: Introduced CROSSTABVIEW (pivot) in PSQL</title>
		<link>https://www.dbrnd.com/2017/04/postgresql-9-6-introduced-crosstabview-pivot-in-psql/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Wed, 12 Apr 2017 16:16:04 +0000</pubDate>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[crosstab]]></category>
		<category><![CDATA[CROSSTABVIEW]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[Pivot]]></category>
		<category><![CDATA[plpgsql]]></category>
		<category><![CDATA[Postgres Query]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[PostgreSQL 9.6]]></category>
		<category><![CDATA[PostgreSQL Administrator]]></category>
		<category><![CDATA[PostgreSQL Error]]></category>
		<category><![CDATA[PostgreSQL Monitoring]]></category>
		<category><![CDATA[PostgreSQL Performance Tuning]]></category>
		<category><![CDATA[PostgreSQL Programming]]></category>
		<category><![CDATA[PostgreSQL Tips and Tricks]]></category>
		<category><![CDATA[psql]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=5020</guid>

					<description><![CDATA[In this post, I am sharing a new feature CROSSTABVIEW in PSQL of PostgreSQL 9.6. Many times we require data arrangement horizontally, instead of vertically. Something like we are doing in a spreadsheet where one element has a multiple child elements and require calculation horizontally for each group of items. Now, you can use CROSSTABVIEW [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F04%2Fpostgresql-9-6-introduced-crosstabview-pivot-in-psql%2F&amp;linkname=PostgreSQL%209.6%3A%20Introduced%20CROSSTABVIEW%20%28pivot%29%20in%20PSQL" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F04%2Fpostgresql-9-6-introduced-crosstabview-pivot-in-psql%2F&amp;linkname=PostgreSQL%209.6%3A%20Introduced%20CROSSTABVIEW%20%28pivot%29%20in%20PSQL" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F04%2Fpostgresql-9-6-introduced-crosstabview-pivot-in-psql%2F&amp;linkname=PostgreSQL%209.6%3A%20Introduced%20CROSSTABVIEW%20%28pivot%29%20in%20PSQL" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F04%2Fpostgresql-9-6-introduced-crosstabview-pivot-in-psql%2F&amp;linkname=PostgreSQL%209.6%3A%20Introduced%20CROSSTABVIEW%20%28pivot%29%20in%20PSQL" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F04%2Fpostgresql-9-6-introduced-crosstabview-pivot-in-psql%2F&amp;linkname=PostgreSQL%209.6%3A%20Introduced%20CROSSTABVIEW%20%28pivot%29%20in%20PSQL" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F04%2Fpostgresql-9-6-introduced-crosstabview-pivot-in-psql%2F&amp;linkname=PostgreSQL%209.6%3A%20Introduced%20CROSSTABVIEW%20%28pivot%29%20in%20PSQL" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F04%2Fpostgresql-9-6-introduced-crosstabview-pivot-in-psql%2F&#038;title=PostgreSQL%209.6%3A%20Introduced%20CROSSTABVIEW%20%28pivot%29%20in%20PSQL" data-a2a-url="https://www.dbrnd.com/2017/04/postgresql-9-6-introduced-crosstabview-pivot-in-psql/" data-a2a-title="PostgreSQL 9.6: Introduced CROSSTABVIEW (pivot) in PSQL"></a></p><p>In this post, I am sharing a new feature CROSSTABVIEW in PSQL of PostgreSQL 9.6. Many times we require data arrangement horizontally, instead of vertically. </p>
<p>Something like we are doing in a spreadsheet where one element has a multiple child elements and require calculation horizontally for each group of items.</p>
<p>Now, you can use CROSSTABVIEW in new PSQL for this kind of requirement.</p>
<p><strong>Below is a small demonstration of this:</strong></p>
<p><strong>Open a psql command line and create a below sample table:</strong></p>
<pre class="crayon-plain-tag">create table tbl_range as
select
    ('{a,b,c,d,e,f}'::text[])[1 + floor(random() * 6)] as data1
    ,('{g,h,i,j,k,l}'::text[])[1 + floor(random() * 6)] as data2
    ,random() * 1000 as randomnumber
from generate_series(1,10000);</pre> </p>
<p><strong>Execute below few SELECTs:</strong></p>
<pre class="crayon-plain-tag">select * from tbl_range;
select data1, data2, count(*) from tbl_range group by data1, data2;</pre> </p>
<p><strong>Now check sample SELECT with CROSSTABVIEW:</strong></p>
<pre class="crayon-plain-tag">select data1, data2, count(*) from tbl_range group by data1, data2 \crosstabview data1 data2 count;</pre> </p>
<p><strong>The result:</strong></p>
<pre class="crayon-plain-tag">dbrnd=# select data1, data2, count(*) from tbl_range group by data1, data2 \crosstabview data1 data2 count;
 data1 |  k  |  j  |  i  |  h  |  g  |  l
-------+-----+-----+-----+-----+-----+-----
 f     | 281 | 273 | 261 | 265 | 268 | 258
 a     | 288 | 293 | 278 | 293 | 248 | 279
 d     | 293 | 264 | 278 | 258 | 289 | 291
 c     | 272 | 276 | 292 | 287 | 263 | 281
 e     | 269 | 279 | 281 | 257 | 274 | 318
 b     | 289 | 270 | 301 | 295 | 247 | 291
(6 rows)</pre> </p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>PostgreSQL: Shell script to copy table data from one server to another server</title>
		<link>https://www.dbrnd.com/2017/03/postgresql-shell-script-to-copy-table-data-from-one-server-to-another-server-psql-copy-command-data-migration/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Thu, 02 Mar 2017 16:16:00 +0000</pubDate>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[PostgreSQL DBA Script]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[Bash shell script]]></category>
		<category><![CDATA[Copy command]]></category>
		<category><![CDATA[data migration]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[plpgsql]]></category>
		<category><![CDATA[Postgres Query]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[PostgreSQL Administrator]]></category>
		<category><![CDATA[PostgreSQL Error]]></category>
		<category><![CDATA[PostgreSQL Monitoring]]></category>
		<category><![CDATA[PostgreSQL Performance Tuning]]></category>
		<category><![CDATA[PostgreSQL Programming]]></category>
		<category><![CDATA[PostgreSQL Tips and Tricks]]></category>
		<category><![CDATA[psql]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=4672</guid>

					<description><![CDATA[Recently, I shared one article on PostgreSQL schemas migration. PostgreSQL: Script to copy Table Data from one Schema to another Schema The migration activities are very common for all DBAs. I found lots of different questions on migration exercises. In this post, I am sharing a Linux shell script to copy your table data from [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F03%2Fpostgresql-shell-script-to-copy-table-data-from-one-server-to-another-server-psql-copy-command-data-migration%2F&amp;linkname=PostgreSQL%3A%20Shell%20script%20to%20copy%20table%20data%20from%20one%20server%20to%20another%20server" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F03%2Fpostgresql-shell-script-to-copy-table-data-from-one-server-to-another-server-psql-copy-command-data-migration%2F&amp;linkname=PostgreSQL%3A%20Shell%20script%20to%20copy%20table%20data%20from%20one%20server%20to%20another%20server" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F03%2Fpostgresql-shell-script-to-copy-table-data-from-one-server-to-another-server-psql-copy-command-data-migration%2F&amp;linkname=PostgreSQL%3A%20Shell%20script%20to%20copy%20table%20data%20from%20one%20server%20to%20another%20server" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F03%2Fpostgresql-shell-script-to-copy-table-data-from-one-server-to-another-server-psql-copy-command-data-migration%2F&amp;linkname=PostgreSQL%3A%20Shell%20script%20to%20copy%20table%20data%20from%20one%20server%20to%20another%20server" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F03%2Fpostgresql-shell-script-to-copy-table-data-from-one-server-to-another-server-psql-copy-command-data-migration%2F&amp;linkname=PostgreSQL%3A%20Shell%20script%20to%20copy%20table%20data%20from%20one%20server%20to%20another%20server" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F03%2Fpostgresql-shell-script-to-copy-table-data-from-one-server-to-another-server-psql-copy-command-data-migration%2F&amp;linkname=PostgreSQL%3A%20Shell%20script%20to%20copy%20table%20data%20from%20one%20server%20to%20another%20server" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F03%2Fpostgresql-shell-script-to-copy-table-data-from-one-server-to-another-server-psql-copy-command-data-migration%2F&#038;title=PostgreSQL%3A%20Shell%20script%20to%20copy%20table%20data%20from%20one%20server%20to%20another%20server" data-a2a-url="https://www.dbrnd.com/2017/03/postgresql-shell-script-to-copy-table-data-from-one-server-to-another-server-psql-copy-command-data-migration/" data-a2a-title="PostgreSQL: Shell script to copy table data from one server to another server"></a></p><p>Recently, I shared one article on PostgreSQL schemas migration. </p>
<blockquote data-secret="dbPEectos8" class="wp-embedded-content"><p><a href="https://www.dbrnd.com/2017/02/postgresql-script-to-copy-schema-table-data-to-another-schema-table-migration/">PostgreSQL: Script to copy Table Data from one Schema to another Schema</a></p></blockquote>
<p><iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2017/02/postgresql-script-to-copy-schema-table-data-to-another-schema-table-migration/embed/#?secret=dbPEectos8" data-secret="dbPEectos8" width="600" height="338" title="&#8220;PostgreSQL: Script to copy Table Data from one Schema to another Schema&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<p>The migration activities are very common for all DBAs. I found lots of different questions on migration exercises.<br />
In this post, I am sharing a Linux shell script to copy your table data from one PostgreSQL Server to another PostgreSQL Server using psql command line. </p>
<blockquote><p>I am just migrating the data; please create a blank table at your destination/second database server. </p>
<p>This is a utility script. Further, you can modify the script for generic use something like by adding parameters for host_name, database_name, table_name and others</p></blockquote>
<p><strong>Linux Bash Shell Script for data migration between PostgreSQL Servers:</strong></p>
<pre class="crayon-plain-tag">#!/bin/bash
psql \
    -X \
    -U user_name \
    -h host_name1 \
    -d database_name \
    -c "\\copy tbl_Students to stdout" \
| \
psql \
    -X \
    -U user_name \
    -h host_name2 \
    -d database_name \
    -c "\\copy tbl_Students from stdin"</pre> </p>
<p><strong>You can also filter the column list something like below script:</strong></p>
<pre class="crayon-plain-tag">#!/bin/bash
psql \
    -X \
    -U user_name \
    -h host_name1 \
    -d database_name \
    -c "\\copy (SELECT Rno, Studname FROM tbl_Students) to stdout" \
| \
psql \
    -X \
    -U user_name \
    -h host_name2 \
    -d database_name \
    -c "\\copy tbl_Students from stdin"</pre> </p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>PostgreSQL: Shell script to store psql SELECT output into Variable</title>
		<link>https://www.dbrnd.com/2017/03/postgresql-shell-script-to-store-psql-select-output-into-variable/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Wed, 01 Mar 2017 16:16:54 +0000</pubDate>
				<category><![CDATA[Bash Shell Script]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[Bash shell script]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[Linux Variable]]></category>
		<category><![CDATA[plpgsql]]></category>
		<category><![CDATA[Postgres Query]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[PostgreSQL Administrator]]></category>
		<category><![CDATA[PostgreSQL Error]]></category>
		<category><![CDATA[PostgreSQL Monitoring]]></category>
		<category><![CDATA[PostgreSQL Performance Tuning]]></category>
		<category><![CDATA[PostgreSQL Programming]]></category>
		<category><![CDATA[PostgreSQL Tips and Tricks]]></category>
		<category><![CDATA[psql]]></category>
		<category><![CDATA[Record count]]></category>
		<category><![CDATA[Shell script]]></category>
		<category><![CDATA[Tuple]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=4666</guid>

					<description><![CDATA[In the previous post, I shared shell script like store psql result into record array. In this post, I am sharing one more shell script to store the result of psql SELECT query into a Variable of Bash Shell Script. This handy script is useful for a beginner who just started to write a PostgreSQL [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F03%2Fpostgresql-shell-script-to-store-psql-select-output-into-variable%2F&amp;linkname=PostgreSQL%3A%20Shell%20script%20to%20store%20psql%20SELECT%20output%20into%20Variable" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F03%2Fpostgresql-shell-script-to-store-psql-select-output-into-variable%2F&amp;linkname=PostgreSQL%3A%20Shell%20script%20to%20store%20psql%20SELECT%20output%20into%20Variable" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F03%2Fpostgresql-shell-script-to-store-psql-select-output-into-variable%2F&amp;linkname=PostgreSQL%3A%20Shell%20script%20to%20store%20psql%20SELECT%20output%20into%20Variable" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F03%2Fpostgresql-shell-script-to-store-psql-select-output-into-variable%2F&amp;linkname=PostgreSQL%3A%20Shell%20script%20to%20store%20psql%20SELECT%20output%20into%20Variable" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F03%2Fpostgresql-shell-script-to-store-psql-select-output-into-variable%2F&amp;linkname=PostgreSQL%3A%20Shell%20script%20to%20store%20psql%20SELECT%20output%20into%20Variable" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F03%2Fpostgresql-shell-script-to-store-psql-select-output-into-variable%2F&amp;linkname=PostgreSQL%3A%20Shell%20script%20to%20store%20psql%20SELECT%20output%20into%20Variable" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F03%2Fpostgresql-shell-script-to-store-psql-select-output-into-variable%2F&#038;title=PostgreSQL%3A%20Shell%20script%20to%20store%20psql%20SELECT%20output%20into%20Variable" data-a2a-url="https://www.dbrnd.com/2017/03/postgresql-shell-script-to-store-psql-select-output-into-variable/" data-a2a-title="PostgreSQL: Shell script to store psql SELECT output into Variable"></a></p><p>In the previous post, I shared shell script like store psql result into record array.<br />
In this post, I am sharing one more shell script to store the result of psql SELECT query into a Variable of Bash Shell Script. </p>
<p>This handy script is useful for a beginner who just started to write a PostgreSQL DBA Bash Shell Script. You need this kind of demonstration to store the result of psql query into variable mostly like count of records. </p>
<p>The value of this variable we can use for further validation something like data exists or not in the Table.</p>
<blockquote><p>In the below script, I used two variables to store the count of a table, but do not forget to notice option &#8216;-t&#8217; in the second query which returns only tuple value and without option &#8216;-t&#8217; it returns all formatted text as well like column name, returned a row count. </p>
<p>We need only tuple value so we must use &#8216;-t&#8217; option. Please check the below demonstration.
</p></blockquote>
<pre class="crayon-plain-tag">#!/bin/bash

DB_NAME=$1
RecordCount1=$( psql -d ${DB_NAME} -c "select count(1) from tbl_students" )
RecordCount2=$( psql -d ${DB_NAME} -t -c "select count(1) from tbl_students" )

echo "RecordCount1:"$RecordCount1
echo "RecordCount2:"$RecordCount2</pre> </p>
<p><strong>The result:</strong></p>
<pre class="crayon-plain-tag">RecordCount1: count ------- 9 (1 row)
RecordCount2: 9</pre> </p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>PostgreSQL: Shell script to store psql result in RECORD ARRAY using WHILE LOOP</title>
		<link>https://www.dbrnd.com/2017/02/postgresql-shell-script-to-store-psql-result-in-record-array-using-while-loop/</link>
					<comments>https://www.dbrnd.com/2017/02/postgresql-shell-script-to-store-psql-result-in-record-array-using-while-loop/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Tue, 28 Feb 2017 16:16:46 +0000</pubDate>
				<category><![CDATA[Bash Shell Script]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[Bash shell script]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[plpgsql]]></category>
		<category><![CDATA[Postgres Query]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[PostgreSQL Administrator]]></category>
		<category><![CDATA[PostgreSQL Error]]></category>
		<category><![CDATA[PostgreSQL Monitoring]]></category>
		<category><![CDATA[PostgreSQL Performance Tuning]]></category>
		<category><![CDATA[PostgreSQL Programming]]></category>
		<category><![CDATA[PostgreSQL Tips and Tricks]]></category>
		<category><![CDATA[psql]]></category>
		<category><![CDATA[RECORD ARRAY]]></category>
		<category><![CDATA[Shell script]]></category>
		<category><![CDATA[WHILE LOOP]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=4664</guid>

					<description><![CDATA[Now a day, I am developing different Linux shell scripts to monitor the PostgreSQL database server. Later, I will share those shell scripts. But before that, I want to share few basic things which we can embed in any one of our Shell scripts. In this post, I am sharing a small shell script to [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F02%2Fpostgresql-shell-script-to-store-psql-result-in-record-array-using-while-loop%2F&amp;linkname=PostgreSQL%3A%20Shell%20script%20to%20store%20psql%20result%20in%20RECORD%20ARRAY%20using%20WHILE%20LOOP" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F02%2Fpostgresql-shell-script-to-store-psql-result-in-record-array-using-while-loop%2F&amp;linkname=PostgreSQL%3A%20Shell%20script%20to%20store%20psql%20result%20in%20RECORD%20ARRAY%20using%20WHILE%20LOOP" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F02%2Fpostgresql-shell-script-to-store-psql-result-in-record-array-using-while-loop%2F&amp;linkname=PostgreSQL%3A%20Shell%20script%20to%20store%20psql%20result%20in%20RECORD%20ARRAY%20using%20WHILE%20LOOP" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F02%2Fpostgresql-shell-script-to-store-psql-result-in-record-array-using-while-loop%2F&amp;linkname=PostgreSQL%3A%20Shell%20script%20to%20store%20psql%20result%20in%20RECORD%20ARRAY%20using%20WHILE%20LOOP" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F02%2Fpostgresql-shell-script-to-store-psql-result-in-record-array-using-while-loop%2F&amp;linkname=PostgreSQL%3A%20Shell%20script%20to%20store%20psql%20result%20in%20RECORD%20ARRAY%20using%20WHILE%20LOOP" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F02%2Fpostgresql-shell-script-to-store-psql-result-in-record-array-using-while-loop%2F&amp;linkname=PostgreSQL%3A%20Shell%20script%20to%20store%20psql%20result%20in%20RECORD%20ARRAY%20using%20WHILE%20LOOP" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F02%2Fpostgresql-shell-script-to-store-psql-result-in-record-array-using-while-loop%2F&#038;title=PostgreSQL%3A%20Shell%20script%20to%20store%20psql%20result%20in%20RECORD%20ARRAY%20using%20WHILE%20LOOP" data-a2a-url="https://www.dbrnd.com/2017/02/postgresql-shell-script-to-store-psql-result-in-record-array-using-while-loop/" data-a2a-title="PostgreSQL: Shell script to store psql result in RECORD ARRAY using WHILE LOOP"></a></p><p>Now a day, I am developing different Linux shell scripts to monitor the PostgreSQL database server. Later, I will share those shell scripts.</p>
<p>But before that, I want to share few basic things which we can embed in any one of our Shell scripts.</p>
<p>In this post, I am sharing a small shell script to iterate the result of psql SELECT using RECORD ARRAY and WHILE LOOP.<br />
Using that, we can do further processing and validation on each record.</p>
<p><strong>Script to iterate the table result:</strong><br />
<pre class="crayon-plain-tag">#!/bin/bash

DB_NAME=$1
psql -d ${DB_NAME} -At -c "select rno, studname, studclass from tbl_students" \
    | while read -a Record ; do
    rno=${Record[0]}
    studname=${Record[1]}
    studclass=${Record[2]}

    echo "${rno} ${studname} ${studclass}"
done</pre>
<strong>The result:</strong><br />
<pre class="crayon-plain-tag">rno | studname
-----+----------+-----------
1 | Anvesh
2 | Neevan
3 | Toby
5 | Roy
4 | Jenny
6 | Kaviy
7 | Martin
8 | Laxmi
9 | Nion
(9 rows)</pre>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2017/02/postgresql-shell-script-to-store-psql-result-in-record-array-using-while-loop/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
	</channel>
</rss>
