<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>PostgreSQL on Wael Nasreddine</title><link>https://risala.pages.dev/tags/pg/</link><description>Recent content in PostgreSQL on Wael Nasreddine</description><generator>Hugo</generator><language>en-us</language><atom:link href="https://risala.pages.dev/tags/pg/index.xml" rel="self" type="application/rss+xml"/><item><title>PostgreSQL - Create Role for a Database</title><link>https://risala.pages.dev/posts/pg-create-role-for-a-db/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://risala.pages.dev/posts/pg-create-role-for-a-db/</guid><description>&lt;h1 id="postgresql---create-role-for-a-database"&gt;&#10; PostgreSQL - Create Role for a Database&#10; &lt;a class="heading-link" href="#postgresql---create-role-for-a-database"&gt;&#10; &lt;i class="fa-solid fa-link" aria-hidden="true" title="Link to heading"&gt;&lt;/i&gt;&#10; &lt;span class="sr-only"&gt;Link to heading&lt;/span&gt;&#10; &lt;/a&gt;&#10;&lt;/h1&gt;&#10;&lt;h2 id="problem"&gt;&#10; Problem&#10; &lt;a class="heading-link" href="#problem"&gt;&#10; &lt;i class="fa-solid fa-link" aria-hidden="true" title="Link to heading"&gt;&lt;/i&gt;&#10; &lt;span class="sr-only"&gt;Link to heading&lt;/span&gt;&#10; &lt;/a&gt;&#10;&lt;/h2&gt;&#10;&lt;p&gt;I want to create a role that has all permissions on a database (owner of such database) so the application can do whatever it needs within the db.&lt;/p&gt;&#10;&lt;h2 id="solution"&gt;&#10; Solution&#10; &lt;a class="heading-link" href="#solution"&gt;&#10; &lt;i class="fa-solid fa-link" aria-hidden="true" title="Link to heading"&gt;&lt;/i&gt;&#10; &lt;span class="sr-only"&gt;Link to heading&lt;/span&gt;&#10; &lt;/a&gt;&#10;&lt;/h2&gt;&#10;&lt;p&gt;First &lt;a href="https://risala.pages.dev/posts/pg-create-utf-8-db/" &gt;PostgreSQL - Create UTF-8 Database&lt;/a&gt;.&lt;/p&gt;&#10;&lt;pre&gt;&lt;code&gt;CREATE ROLE &amp;quot;role_name&amp;quot; WITH LOGIN PASSWORD '&amp;lt;password&amp;gt;';&#10;ALTER DATABASE &amp;quot;db_name&amp;quot; OWNER TO &amp;quot;role_name&amp;quot;;&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;h2 id="related"&gt;&#10; Related&#10; &lt;a class="heading-link" href="#related"&gt;&#10; &lt;i class="fa-solid fa-link" aria-hidden="true" title="Link to heading"&gt;&lt;/i&gt;&#10; &lt;span class="sr-only"&gt;Link to heading&lt;/span&gt;&#10; &lt;/a&gt;&#10;&lt;/h2&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;&lt;a href="https://risala.pages.dev/posts/pg-create-utf-8-db/" &gt;PostgreSQL - Create UTF-8 Database&lt;/a&gt;&lt;/li&gt;&#10;&lt;/ul&gt;</description></item><item><title>PostgreSQL - Create UTF-8 Database</title><link>https://risala.pages.dev/posts/pg-create-utf-8-db/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://risala.pages.dev/posts/pg-create-utf-8-db/</guid><description>&lt;h1 id="postgresql---create-utf-8-database"&gt;&#10; PostgreSQL - Create UTF-8 Database&#10; &lt;a class="heading-link" href="#postgresql---create-utf-8-database"&gt;&#10; &lt;i class="fa-solid fa-link" aria-hidden="true" title="Link to heading"&gt;&lt;/i&gt;&#10; &lt;span class="sr-only"&gt;Link to heading&lt;/span&gt;&#10; &lt;/a&gt;&#10;&lt;/h1&gt;&#10;&lt;h2 id="problem"&gt;&#10; Problem&#10; &lt;a class="heading-link" href="#problem"&gt;&#10; &lt;i class="fa-solid fa-link" aria-hidden="true" title="Link to heading"&gt;&lt;/i&gt;&#10; &lt;span class="sr-only"&gt;Link to heading&lt;/span&gt;&#10; &lt;/a&gt;&#10;&lt;/h2&gt;&#10;&lt;p&gt;I want to create a new database ensuring encoding is set to UTF-8.&lt;/p&gt;&#10;&lt;h2 id="solution"&gt;&#10; Solution&#10; &lt;a class="heading-link" href="#solution"&gt;&#10; &lt;i class="fa-solid fa-link" aria-hidden="true" title="Link to heading"&gt;&lt;/i&gt;&#10; &lt;span class="sr-only"&gt;Link to heading&lt;/span&gt;&#10; &lt;/a&gt;&#10;&lt;/h2&gt;&#10;&lt;pre&gt;&lt;code&gt;CREATE DATABASE &amp;quot;db_name&amp;quot; WITH ENCODING = 'UTF8';&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;h2 id="related"&gt;&#10; Related&#10; &lt;a class="heading-link" href="#related"&gt;&#10; &lt;i class="fa-solid fa-link" aria-hidden="true" title="Link to heading"&gt;&lt;/i&gt;&#10; &lt;span class="sr-only"&gt;Link to heading&lt;/span&gt;&#10; &lt;/a&gt;&#10;&lt;/h2&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;&lt;a href="https://risala.pages.dev/posts/pg-create-role-for-a-db/" &gt;PostgreSQL - Create Role for a Database&lt;/a&gt;&lt;/li&gt;&#10;&lt;/ul&gt;</description></item><item><title>PostgreSQL - psql using URI</title><link>https://risala.pages.dev/posts/pg-psql-with-uri/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://risala.pages.dev/posts/pg-psql-with-uri/</guid><description>&lt;h2 id="problem"&gt;&#10; Problem&#10; &lt;a class="heading-link" href="#problem"&gt;&#10; &lt;i class="fa-solid fa-link" aria-hidden="true" title="Link to heading"&gt;&lt;/i&gt;&#10; &lt;span class="sr-only"&gt;Link to heading&lt;/span&gt;&#10; &lt;/a&gt;&#10;&lt;/h2&gt;&#10;&lt;p&gt;I have a PostgreSQL URI for one of my applications, a URI such as &lt;code&gt;postgres://username:password@hostname:port/database-name&lt;/code&gt; and I need to connect to the database from the command-line&lt;/p&gt;&#10;&lt;h2 id="solution"&gt;&#10; Solution&#10; &lt;a class="heading-link" href="#solution"&gt;&#10; &lt;i class="fa-solid fa-link" aria-hidden="true" title="Link to heading"&gt;&lt;/i&gt;&#10; &lt;span class="sr-only"&gt;Link to heading&lt;/span&gt;&#10; &lt;/a&gt;&#10;&lt;/h2&gt;&#10;&lt;p&gt;I used to break the URI into its parts and pass them to &lt;code&gt;psql&lt;/code&gt; in the usual way (&lt;code&gt;PGPASSWORD&lt;/code&gt; for the password, &lt;code&gt;-h &amp;lt;host&amp;gt;&lt;/code&gt; for the host, &lt;code&gt;-U &amp;lt;user&amp;gt;&lt;/code&gt; for the user etc..&lt;/p&gt;</description></item><item><title>PostgreSQL - Read-Only PSQL Session</title><link>https://risala.pages.dev/posts/pg-readonly-psql-session/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://risala.pages.dev/posts/pg-readonly-psql-session/</guid><description>&lt;h1 id="problem"&gt;&#10; Problem&#10; &lt;a class="heading-link" href="#problem"&gt;&#10; &lt;i class="fa-solid fa-link" aria-hidden="true" title="Link to heading"&gt;&lt;/i&gt;&#10; &lt;span class="sr-only"&gt;Link to heading&lt;/span&gt;&#10; &lt;/a&gt;&#10;&lt;/h1&gt;&#10;&lt;p&gt;I want to connect to a database ensuring that I cannot perform any write operations&lt;/p&gt;&#10;&lt;h1 id="solution"&gt;&#10; Solution&#10; &lt;a class="heading-link" href="#solution"&gt;&#10; &lt;i class="fa-solid fa-link" aria-hidden="true" title="Link to heading"&gt;&lt;/i&gt;&#10; &lt;span class="sr-only"&gt;Link to heading&lt;/span&gt;&#10; &lt;/a&gt;&#10;&lt;/h1&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;&#10;&lt;p&gt;Connect to a PostgreSQL server with psql or your graphical interface. This guide &lt;strong&gt;has only been tested with psql&lt;/strong&gt;.&lt;/p&gt;&#10;&lt;/li&gt;&#10;&lt;li&gt;&#10;&lt;p&gt;Connect to the database you'd like to explore with &lt;code&gt;\c dbname&lt;/code&gt;&lt;/p&gt;&#10;&lt;/li&gt;&#10;&lt;li&gt;&#10;&lt;p&gt;Run the following command:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-sql" data-lang="sql"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;SET&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;SESSION&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;CHARACTERISTICS&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;AS&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;TRANSACTION&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;READ&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;ONLY&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;h1 id="related"&gt;&#10; Related&#10; &lt;a class="heading-link" href="#related"&gt;&#10; &lt;i class="fa-solid fa-link" aria-hidden="true" title="Link to heading"&gt;&lt;/i&gt;&#10; &lt;span class="sr-only"&gt;Link to heading&lt;/span&gt;&#10; &lt;/a&gt;&#10;&lt;/h1&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;&lt;a href="https://stackoverflow.com/a/71023224%5D%28https://stackoverflow.com/a/71023224%29" class="external-link" target="_blank" rel="noopener"&gt;https://stackoverflow.com/a/71023224&lt;/a&gt;&lt;/li&gt;&#10;&lt;li&gt;&lt;a href="https://www.postgresql.org/docs/15/sql-set-transaction.html%5D%28https://www.postgresql.org/docs/15/sql-set-transaction.html%29" class="external-link" target="_blank" rel="noopener"&gt;https://www.postgresql.org/docs/15/sql-set-transaction.html&lt;/a&gt;&lt;/li&gt;&#10;&lt;/ul&gt;</description></item></channel></rss>