title: Could not connect to server when PostgreSQL at new storage location
body: <p>I am trying to change the data directory of my PostgreSQL db on my Raspberry pi 4.</p>
  <p>The steps I performed are:</p>
  <ol>
  <li><p>Installing PostgreSQL:</p>
  <blockquote>
  <p>sudo apt install postgresql</p>
  </blockquote>
  </li>
  <li><p>Stopping service:</p>
  <blockquote>
  <p>sudo service postgresql stop</p>
  </blockquote>
  </li>
  <li><p>Move database files (which I tryed in two ways)</p>
  <blockquote>
  <p>sudo mv /var/lib/postgresql/11/main /mnt/storage/postgres</p>
  </blockquote>
  <p>OR</p>
  <blockquote>
  <p>sudo rsync -av /var/lib/postgresql/11/main /mnt/storage/postgres</p>
  </blockquote>
  </li>
  <li><p>Adapting postgresql.conf</p>
  <blockquote>
  <p>data_directory = '/mnt/storage/postgres'</p>
  </blockquote>
  <blockquote>
  <p>listen_addresses = '*'</p>
  </blockquote>
  </li>
  <li><p>Starting service:</p>
  <blockquote>
  <p>sudo service postgresql start</p>
  </blockquote>
  </li>
  </ol>
  <p>With the command &quot;psql&quot; I receive the following output:</p>
  <pre><code>psql: could not connect to server: No such file or directory
          Is the server running locally and accepting
          connections on Unix domain socket &quot;/var/run/postgresql/.s.PGSQL.5432&quot;?
  </code></pre>
  <hr />
  <p>Additional Information:</p>
  <pre><code>$ service postgresql status
  ● postgresql.service - PostgreSQL RDBMS
     Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled)
     Active: active (exited) since Fri 2022-02-04 17:12:29 CET; 31s ago
    Process: 21169 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
   Main PID: 21169 (code=exited, status=0/SUCCESS)
  
  Feb 04 17:12:29 MyPi systemd[1]: Starting PostgreSQL RDBMS...
  Feb 04 17:12:29 MyPi systemd[1]: Started PostgreSQL RDBMS.
  </code></pre>
  <pre><code>$cat /etc/os-release
  PRETTY_NAME=&quot;Raspbian GNU/Linux 10 (buster)&quot;
  NAME=&quot;Raspbian GNU/Linux&quot;
  VERSION_ID=&quot;10&quot;
  VERSION=&quot;10 (buster)&quot;
  VERSION_CODENAME=buster
  ID=raspbian
  ID_LIKE=debian
  HOME_URL=&quot;http://www.raspbian.org/&quot;
  SUPPORT_URL=&quot;http://www.raspbian.org/RaspbianForums&quot;
  BUG_REPORT_URL=&quot;http://www.raspbian.org/RaspbianBugs&quot;
  </code></pre>
  <pre><code>$ psql -V
  psql (PostgreSQL) 11.14 (Raspbian 11.14-0+deb10u1)
  </code></pre>
  <pre><code>$ findmnt
  ...
  /mnt/storage                        /dev/sda1      fuseblk    rw,relatime,user_id=0,group_id=0,default_permissions,allow_other,blksize=4096
  ...
  </code></pre>
  <p><strong>Update:</strong></p>
  <pre><code>$ pg_lsclusters
  Ver Cluster Port Status Owner Data directory                           Log file
  11  main    5432 down   root  /mnt/storage/postgres/postgresql/11/main /var/log/postgresql/postgresql-11-main.log
  </code></pre>
  <p>The location I want to use for the database is an external drive. I played also around with permission and ownership of the mounted external drive. One issue I am experiencing here is that the permissions always return to their initial state after I changed them.</p>
  <pre><code>$ cat /etc/fstab
  ...
  PARTUUID=96082d9d-0e40-4ac9-821b-78d65ae2c3f0 /mnt/storage ntfs-3g auto,users,permissions 0 0
  ...
  </code></pre>