Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

6
  • thank you for this. When I run the initdb command I am getting an error saying: fixing permissions on existing directory /mnt/data/postgresql/12/main ... initdb: error: could not change permissions of directory "/mnt/data/postgresql/12/main": Operation not permitted. I made sure I used sudo but I am assuming since we switched to postgres with -u that the postgres user doesn't have permission to do this? Commented Feb 10, 2021 at 18:00
  • Run sudo chown -R postgres:postgres /mnt/data/postgresql before "initdb", the directory needs to belong to user postgres.
    – Freddy
    Commented Feb 10, 2021 at 18:07
  • That got me through the initdb which looks like I have a bunch of new config files in the /mnt/data/postgresql/12/main folder. I had to do sudo su postgres to be able to CD into it. Can you explain what this did exactly? Commented Feb 10, 2021 at 18:24
  • You don't need to edit the config files in /mnt/data/postgresql/12/main, just change data_directory in /etc/postgresql/12/main/postgresql.conf and start the service. The default password is not set, use sudo to switch to the user. Please read postgresql.org/docs/12/app-initdb.html.
    – Freddy
    Commented Feb 10, 2021 at 18:30
  • 1
    This is the clean way for a new database instance and I think it's the fastest solution to switch the data directory (edit one line in the original config, easy to revert).
    – Freddy
    Commented Feb 10, 2021 at 18:42