<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: lovenic</title>
    <description>The latest articles on Forem by lovenic (@lovenic).</description>
    <link>https://forem.com/lovenic</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F168889%2Fec6878fe-7354-4387-b610-be55643dfe6e.jpeg</url>
      <title>Forem: lovenic</title>
      <link>https://forem.com/lovenic</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/lovenic"/>
    <language>en</language>
    <item>
      <title>How to install PostgreSQL from binaries on Mac OS X Catalina</title>
      <dc:creator>lovenic</dc:creator>
      <pubDate>Sat, 28 Mar 2020 13:40:15 +0000</pubDate>
      <link>https://forem.com/lovenic/how-to-install-postgresql-from-binaries-on-mac-os-x-catalina-o39</link>
      <guid>https://forem.com/lovenic/how-to-install-postgresql-from-binaries-on-mac-os-x-catalina-o39</guid>
      <description>&lt;p&gt;&lt;em&gt;Evening people.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;There are millions ways of installing RDBMS like &lt;em&gt;PostgreSQL&lt;/em&gt; on your laptop in 2k20. Some of them require just a few hits on your keyboard while others ask you to have solid extent of courage and enthusiasm.&lt;/p&gt;

&lt;p&gt;Let's quickly sketch out a list of possible techniques that modern world offers us to make use of PostgreSQL (assuming we're using &lt;em&gt;Mac OS&lt;/em&gt;):&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Brew.&lt;/li&gt;
&lt;li&gt;Docker.&lt;/li&gt;
&lt;li&gt;EDB Postgres.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Source code.&lt;/em&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Describing pros and cons of each of these methods requires separate posts, but if you feel as adventurous as me the day before I'm composing this posts let's get down to business.&lt;/p&gt;

&lt;p&gt;The problem is I haven't found any comprehensive enough description of how to go through the process of installation PostgreSQL from the start to the working database, so I'm making my own.&lt;/p&gt;

&lt;p&gt;We're gonna install PostgreSQL 11.7, 'cause that was what I needed, but you can try different version with presumably the same degree of success (but I won't promise that 😉 ).&lt;/p&gt;

&lt;p&gt;First of all I should say that PostgreSQL has a wonderful and comprehensive &lt;a href="https://www.postgresql.org/docs/11/index.html"&gt;documentation&lt;/a&gt; that I used a lot and you can surely help yourself as well.&lt;/p&gt;

&lt;p&gt;So let's go step by step (I know everyone likes that) towards fully working PostgreSQL on your machine.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Downloading
&lt;/h2&gt;

&lt;p&gt;What we need to make a first step is to prosaically download the sources from the  postgresql site. Here is the &lt;a href="https://www.postgresql.org/ftp/source/"&gt;link&lt;/a&gt;. What you need here is to pick a version you want and download something like &lt;code&gt;postgresql-&amp;lt;your-version&amp;gt;.tar.gz&lt;/code&gt;. It could be &lt;code&gt;postgresql-11.7.tar.gz&lt;/code&gt;. I downloaded to &lt;code&gt;~/Downloads&lt;/code&gt; folder so you can do the same.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Extracting
&lt;/h2&gt;

&lt;p&gt;Just extract the sources from the archive you've just download by &lt;em&gt;double-clicking the file&lt;/em&gt;. Alternatively you can choose any option you like for extracting.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Enter the door
&lt;/h2&gt;

&lt;p&gt;On this step you should have unpacked folder in one of your directories. Again, mine was &lt;code&gt;~/Downloads&lt;/code&gt;, you can have different. This is the time we need to &lt;em&gt;open the terminal&lt;/em&gt; and do some action.&lt;/p&gt;

&lt;p&gt;Let's &lt;code&gt;cd&lt;/code&gt; into the directory you unpacked your copy of the binaries to.&lt;/p&gt;

&lt;p&gt;In my case it was&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd ~/Downloads/postgresql-11.7
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Please don't forget &lt;em&gt;to adjust&lt;/em&gt; folder and version according you what you've got previously.&lt;/p&gt;

&lt;p&gt;You can spend sometime learning what inside of this treasure box and when you're ready to proceed let's to it.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Configuring
&lt;/h2&gt;

&lt;p&gt;This is the most &lt;em&gt;interesting&lt;/em&gt; and &lt;em&gt;important&lt;/em&gt; step. On this step we need to configure the process in a way that &lt;code&gt;make&lt;/code&gt; command will be able to find all required libraries that are already installed on you system to successfully build your fully working PostgreSQL dream.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;lyrical digression&lt;/em&gt;. PostgreSQL offers you multiple variants of installation. And the most basic one doesn't include some important extensions that you will probably need in your software development process. Some of them are: &lt;em&gt;btree_gin&lt;/em&gt; for maintaining indiсes, &lt;em&gt;citext&lt;/em&gt; for a case-insensitive string management, &lt;em&gt;hstore&lt;/em&gt; that helps to store &lt;em&gt;key-value pairs&lt;/em&gt; in a single PostgreSQL value. We'll need that info a bit later, but for now just keep that in mind.&lt;/p&gt;

&lt;p&gt;I'm not honest with you if I say that there are no &lt;code&gt;easy&lt;/code&gt; path to install PostgreSQL from the binaries. Here's the (link)[&lt;a href="https://www.postgresql.org/docs/11/install-short.html"&gt;https://www.postgresql.org/docs/11/install-short.html&lt;/a&gt;] to what even PostgreSQL offers to you to easily shorten you way. Another thing is that didn't work for me. Or for Mac OS.&lt;/p&gt;

&lt;p&gt;So there are few more steps we need to go through before starting to run scripts and build PostgreSQL.&lt;/p&gt;

&lt;h3&gt;
  
  
  4.1 OpenSSL
&lt;/h3&gt;

&lt;p&gt;This was my bottleneck. While configuring there were always something missing. And from reading the logs I understood that it was OpenSSL.&lt;/p&gt;

&lt;p&gt;So what you need here is to make sure you have OpenSSL installed on your machine.&lt;/p&gt;

&lt;p&gt;There is a simple way to verify that:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;openssl version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Yes, without any dashes.&lt;/p&gt;

&lt;p&gt;You would probably get something like &lt;code&gt;OpenSSL 1.1.1d  10 Sep 2019&lt;/code&gt;. If you have older version I would suggest you to upgrade it.&lt;/p&gt;

&lt;p&gt;And here we're gonna leverage the brew helper.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;brew upgrade openssl
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And if you're missing openssl at all try to install it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;brew install openssl
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Hope everything is great on the current phase, so now we need to find out where the openssl library installed on your machine. Easy as duck:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;which openssl
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You would get something similar to &lt;code&gt;/usr/local/opt/openssl@1.1/bin/openssl&lt;/code&gt;. You might have slightly different result, but that doesn't matter unless it's says you don't have openssl at all. The folder we're interested in is two steps back. Meaning that in this case you should throw two slashes off and get &lt;code&gt;/usr/local/opt/openssl@1.1&lt;/code&gt;. Let's remember that as a &lt;code&gt;openssl_folder&lt;/code&gt; and for now just remember that.&lt;/p&gt;

&lt;h3&gt;
  
  
  4.2 Configure with flags
&lt;/h3&gt;

&lt;p&gt;Now we're ready to start configuring our build process. If you've left your downloaded and unpacked &lt;code&gt;postgresql-&amp;lt;your-version&amp;gt;&lt;/code&gt; folder, this is the time to get back:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd ~/Downloads/postgresql-11.7
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Just paste in you path and you're should be good to go.&lt;/p&gt;

&lt;p&gt;Our goal is to run &lt;code&gt;configure&lt;/code&gt; with openssl flag that requires three more flags passed.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;--with-openssl&lt;/code&gt; itself.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;--with-includes&lt;/code&gt; that should be equal to our &lt;code&gt;openssl_folder&lt;/code&gt; with &lt;code&gt;/include postfix&lt;/code&gt;. So you should get something like &lt;code&gt;/usr/local/opt/openssl@1.1/include&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;--with-libraries&lt;/code&gt; that should be equal to our &lt;code&gt;openssl_folder&lt;/code&gt; with &lt;code&gt;lib&lt;/code&gt; postfix. Something similar to &lt;code&gt;/usr/local/opt/openssl@1.1/lib&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let's collect everything together. From inside of your postgresql folder run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;./configure --with-openssl --with-includes=/usr/local/opt/openssl@1.1/include --with-libraries=/usr/local/opt/openssl@1.1/lib
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Be attentive and don't forget to paste paths that &lt;em&gt;you&lt;/em&gt; got. They are not necessary equal to those described above.&lt;/p&gt;

&lt;p&gt;Now please wait some time and make sure there are no errors that your terminal complains about.&lt;/p&gt;

&lt;p&gt;If so, let's get a step further.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Making
&lt;/h2&gt;

&lt;p&gt;Now we should be good to go with the &lt;em&gt;making&lt;/em&gt; our files with the GNU &lt;code&gt;make&lt;/code&gt; utility. Chances are you already have it.&lt;/p&gt;

&lt;p&gt;Remember that explanation about different variants of the PostgreSQL installation. This is the time to leverage that info. So if you need to have everything installed along with docs and extensions, run from the same folder:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;make world
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But if you would like to install plain version just skip the &lt;code&gt;world&lt;/code&gt; and simply run &lt;code&gt;make&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Wait a bit again and if there are still no errors let's get to the installation.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Installation
&lt;/h2&gt;

&lt;p&gt;Based on what you chose the step before you should run&lt;/p&gt;

&lt;p&gt;if your choice was &lt;code&gt;make world&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo make install-world
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;if your choice was just &lt;code&gt;make&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo make install
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It should say that the PostgreSQL is successfully installed. Yay! Half of the way is done if not even more!&lt;/p&gt;

&lt;h2&gt;
  
  
  7. Creating a dedicated user
&lt;/h2&gt;

&lt;p&gt;Now we need to created a separate user in your system for the safety reasons that will be fully responsible for what happening with your PostgreSQL installation.&lt;/p&gt;

&lt;p&gt;This can be done in different manners.&lt;/p&gt;

&lt;p&gt;Best practice is to create user called &lt;code&gt;postgres&lt;/code&gt;. Different ways of installation create that for you, but here we need to do that ourselves.&lt;/p&gt;

&lt;p&gt;I personally went the UI way and followed this &lt;a href="https://www.imore.com/how-create-new-user-account-your-mac"&gt;guide&lt;/a&gt;. You need to name your user &lt;code&gt;postgres&lt;/code&gt; put the password for him.&lt;/p&gt;

&lt;p&gt;There are command-line options for creating users like &lt;code&gt;dscl&lt;/code&gt;, but it didn't work out for me for some reasons.&lt;/p&gt;

&lt;h2&gt;
  
  
  8. Creating the data folder
&lt;/h2&gt;

&lt;p&gt;Now we need to create a data folder that will store all postgresql data.&lt;br&gt;
Chances are you won't have enough permissions without sudo. So run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo mkdir /usr/local/pgsql/data
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Make sure you point that to the correct folder.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;important thing&lt;/em&gt; if you already have that data folder I would suggest to completely remove it unless it has some important data you don't want to lose.&lt;/p&gt;

&lt;h2&gt;
  
  
  9. Who's in charge?
&lt;/h2&gt;

&lt;p&gt;Although we created previous folder under the root user we need to transfer permission to our newly created &lt;code&gt;postgres&lt;/code&gt; user. As simply as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;chown postgres /usr/local/pgsql/data
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Viola. Permission granted.&lt;/p&gt;

&lt;h2&gt;
  
  
  10. Log file
&lt;/h2&gt;

&lt;p&gt;Another small thing we would like to do is to create a log file for our PostgreSQL server. Please run this series of commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo mkdir /var/log/postgresql
sudo touch /var/log/postgresql/server.log
sudo chown postgres /var/log/postgresql
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's remember that file as a &lt;code&gt;server_logfile&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  11. Dive into world with the postgres host
&lt;/h2&gt;

&lt;p&gt;It's time to login as a &lt;code&gt;postgres&lt;/code&gt; user. Just type the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;su - postgres
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and we're under &lt;code&gt;postgres&lt;/code&gt; now.&lt;/p&gt;

&lt;p&gt;Now it's time to find out what shell is used by your &lt;code&gt;postgres&lt;/code&gt; user. Type:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;echo $0&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Why we need to know the shell type? Because we need to store some environment variables to simplify our life a bit.&lt;/p&gt;

&lt;p&gt;So, based on the result of the previous operation let's create &lt;code&gt;~/.bashrc&lt;/code&gt;, &lt;code&gt;/.zshrc&lt;/code&gt; or anything different if you have different output of the &lt;code&gt;echo&lt;/code&gt; command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;touch ~/.zshrc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These are some nifty things we would like to add:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;It's nice to add that path to the &lt;code&gt;$PGDATA&lt;/code&gt; environment variable that will lead to a database cluster path and will save us some time on avoiding passing &lt;code&gt;-D&lt;/code&gt; option when we start a database server.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;So you can open your shell &lt;code&gt;rc&lt;/code&gt; file and paste:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export PGDATA="/usr/local/pgsql/data"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Make sure you correctly point the path we put together in &lt;code&gt;mkdir&lt;/code&gt; command when we created data folder.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Another thing that can ease your life is adding existing postgresql &lt;code&gt;bin folder&lt;/code&gt; to the &lt;code&gt;$PATH&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;To do that please open your shell &lt;code&gt;.rc&lt;/code&gt; file (&lt;code&gt;~/.bashrc&lt;/code&gt;, &lt;code&gt;~/.zshrc&lt;/code&gt;) and paste the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export PATH="$PATH:/usr/local/pgsql/bin"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Don't forget to reload your shell afterwards:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;source ~/.bashrc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or any different shell &lt;code&gt;rc&lt;/code&gt; file that you use.&lt;/p&gt;

&lt;p&gt;Adding path to executable saves you time to skip prepending commands like &lt;code&gt;createuser&lt;/code&gt;, &lt;code&gt;pg_ctl&lt;/code&gt; and obviously &lt;code&gt;postgres&lt;/code&gt; with the full path.&lt;/p&gt;

&lt;h2&gt;
  
  
  12. Initializing the data cluster
&lt;/h2&gt;

&lt;p&gt;So the full command requires a apth to the executables and a &lt;code&gt;-D&lt;/code&gt; flag as a path to the data cluster folder. Since we added the &lt;code&gt;$PGDATA&lt;/code&gt; environment variable we can skip &lt;code&gt;-D&lt;/code&gt; option and also we can skip writing full path to the executable, 'cause we added that to the &lt;code&gt;$PATH&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;So let's do that:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;initdb
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If everything is okay let's move forward.&lt;/p&gt;

&lt;h2&gt;
  
  
  13. Starting the server
&lt;/h2&gt;

&lt;p&gt;Starting the server requires a logfile parameter by passing the &lt;code&gt;-l&lt;/code&gt; flag. Remember that &lt;code&gt;server_logfile&lt;/code&gt; that we created. We'll use &lt;code&gt;pg_ctl&lt;/code&gt; utility. So starting the server now as easy as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pg_ctl -l /var/log/postgresql/server.log start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As a result you get a brand new postgresql daemon process which pid is located in the &lt;code&gt;/usr/local/pgsql/data/postmaster.pid&lt;/code&gt; so you can always check that out and kill it if you need.&lt;/p&gt;

&lt;p&gt;You can also run that with plain &lt;code&gt;postgresql&lt;/code&gt; command o start the server:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/usr/local/pgsql/bin/postgres &amp;gt; /var/log/postgresql/server.log 2&amp;gt;&amp;amp;1 &amp;amp;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That appendix in the end is needed for running the server in the background.&lt;/p&gt;

&lt;h2&gt;
  
  
  14. Creating first database
&lt;/h2&gt;

&lt;p&gt;Congrats! Now you have a working PostgreSQL server.&lt;/p&gt;

&lt;p&gt;You can try to create a new database:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;createdb test
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And connect to it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;psql test
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So, basically that's it! Remember that you should do everything under &lt;code&gt;postgres&lt;/code&gt; user and don't forget to log out from it when you're done.&lt;/p&gt;

&lt;h2&gt;
  
  
  Bonus: Rails setup
&lt;/h2&gt;

&lt;h3&gt;
  
  
  database.yml
&lt;/h3&gt;

&lt;p&gt;I faced a few issues when connecting to the database server created this way. So, you should be very attentive in constructing your &lt;code&gt;config/database.yml&lt;/code&gt; file. The most important thing here is to put &lt;code&gt;host: localhost&lt;/code&gt; pair and don't forget to insert correct username and password. So your &lt;code&gt;config/database.yml&lt;/code&gt; should look approx like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;default: &amp;amp;default
 adapter: postgresql
 encoding: unicode
 username: postgres
 password: &amp;lt;your-password&amp;gt;
 host: localhost
 pool: 5

development:
 &amp;lt;&amp;lt;: *default
 database: something_development
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rails db:create
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And if you see the encoding error I invite you to the next section.&lt;/p&gt;

&lt;h3&gt;
  
  
  Endcoding
&lt;/h3&gt;

&lt;p&gt;By default template tables in the PostgreSQL have &lt;code&gt;SQL_ASCII&lt;/code&gt; encoding where you might need &lt;code&gt;unicode&lt;/code&gt;. So, here's how to fix that.&lt;/p&gt;

&lt;p&gt;Firstly run &lt;code&gt;psql&lt;/code&gt; under &lt;code&gt;postgres&lt;/code&gt; user so you can influence your databases and run these series of commands to adjust template tables encoding:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;UPDATE pg_database SET datistemplate = FALSE WHERE datname = 'template1';
DROP DATABASE template1;
CREATE DATABASE template1 WITH TEMPLATE = template0 ENCODING = 'UNICODE';
UPDATE pg_database SET datistemplate = TRUE WHERE datname = 'template1';
\c template1
VACUUM FREEZE;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Essentially this is the excerpt from the stackoverflow (answer)[&lt;a href="https://stackoverflow.com/a/16737776"&gt;https://stackoverflow.com/a/16737776&lt;/a&gt;].&lt;/p&gt;

&lt;p&gt;That's it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Epilogue
&lt;/h2&gt;

&lt;p&gt;You may ask why you need to do all that stuff instead of making use of the Docker and do most of that in a minute? I don't know. Probably you just enjoy the process.&lt;/p&gt;

&lt;p&gt;At last I would like to say that putting together a perfect PostgreSQL installation guide is definitely not the goal. I just want to help people like me to overcome some issues while building PostgreSQL from the source code. Please feel free to leave comments and... hope you enjoyed!&lt;/p&gt;

&lt;p&gt;🙏&lt;/p&gt;

&lt;p&gt;References:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.postgresql.org/docs/11/index.html"&gt;https://www.postgresql.org/docs/11/index.html&lt;/a&gt;&lt;br&gt;
&lt;a href="https://medium.com/@kevinmircovich/pg-connectionbad-could-not-connect-to-server-no-such-file-or-directory-da18a3764a0a"&gt;https://medium.com/@kevinmircovich/pg-connectionbad-could-not-connect-to-server-no-such-file-or-directory-da18a3764a0a&lt;/a&gt;&lt;br&gt;
&lt;a href="https://stackoverflow.com/a/16737776"&gt;https://stackoverflow.com/a/16737776&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.imore.com/how-create-new-user-account-your-mac"&gt;https://www.imore.com/how-create-new-user-account-your-mac&lt;/a&gt;&lt;br&gt;
&lt;a href="https://labs.wordtothewise.com/postgresql-osx/"&gt;https://labs.wordtothewise.com/postgresql-osx/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>rails</category>
      <category>postgres</category>
      <category>database</category>
    </item>
  </channel>
</rss>
