How to install Postgresql with a larger data directory

Hi, I’m new to this group so apologies if this is something I should know.

I have used postgresql casually for several years but am wanting more space in my data directory.
I found: Setting up PostgreSQL Database Server :: Fedora Docs and believe I followed the instructions.
However when I run initdb I get the message:

initdb: error: directory “/var/lib/pgsql” exists but is not empty
initdb: detail: It contains a dot-prefixed/invisible file, perhaps due to it being a mount point.
initdb: hint: Using a mount point directly as the data directory is not recommended.
Create a subdirectory under the mount point.
pg_ctl: database system initialization failed

There is a warning that it is a bad idea to have /var/lib or /var/lib/pgsql as mount points.
My understanding is that the datadirectory is /var/lib/pgsql, and I cannot make a subdirectory under it.

Can someone clarify that the ‘postgres-setup’ webpage is still valid or if there is something I have misunderstood. .

Thankyou

What is your disk setup? Share lsblk -f
Where is the disk space you want to use?

It should be possible to use a separate partition for the postgresql database storage.
Have you read the postgresql docs on configuring storage?

The only issue I can think of with using mounted storage is to make sure systemd mounts the partition before postgresql service starts, which is easy to do.

1 Like

Hi Barry,
I read the ‘setting up PostgresSQL Database Server’ mentioned above.
I have been through a number of combinations of starting and stopping the Postgres service, and mounting and unmounting the drive so do not believe the order in systemd is an problem.
I have a / partition and have set up a LVM partition, which I want to use as data directory.

My lsblk -f (with other disks) is:

lsblk -f
NAME FSTYPE FSVER LABEL UUID FSAVAIL FSUSE% MOUNTPOINTS
sda xfs 7ba7ed29-092e-41cb-be7f-9d91a4502780 148.1G 96% /home
sdb LVM2_member LVM2 001 B2zqxn-IEkS-4vt6-PmSF-OpAh-PD2k-EpLjdc
└─vg_store-pgsql
xfs 1aaeac90-d271-47dc-bf88-66bac83708e4
sdc
└─sdc1 btrfs home2022 d2308528-379d-4c95-b199-0bf283210234
sdd
└─sdd1 xfs f6708b84-5172-4a42-9ad1-74a306115381 1.2T 35% /home/hugh/gisData
sde
sdf
sdg
sdh
zram0 swap 1 zram0 10fbfb0c-4b80-498c-a826-e34147ce0e58 [SWAP]
swap 1 7ed2b897-1fab-480b-b731-5badb964e175
nvme1n1
├─nvme1n1p1

├─nvme1n1p2
│ ext4 1.0 270f616e-4491-49a6-8d72-83cbdc01ab62 137.7G 23% /
└─nvme1n1p3
swap 1 73c31552-db3a-402d-ae73-b3c53df3fa59 [SWAP]

An trimmed version of my df is:
/dev/mapper/vg_store-pgsql 838451200 16088380 822362820 2% /var/lib/pgsql
/dev/nvme1n1p2 201263328 46618312 144348596 25% /

I am familiar with the postgres documentation for moving the data directory, but my understanding is that Fedora forces initdb to use /var/lib/psql. The Fedora documentation indicates (and my experiance is) that initdb -D OTHER/PATH does not work.

I am running the current release system (fedora 6.14.9-300.fc42.x86_64)

You don’t really need to reinit the database.
Assuming that you have properly mounted the volume.
Stop the service, transfer the data, start the service:

sudo systemctl stop postgresql.service
sudo mount $(lsblk -n -o PATH -Q 'MOUNTPOINTS=="/"') /mnt
sudo cp -f -a /mnt/var/lib/pgsql/. /var/lib/pgsql
sudo umount /mnt
sudo systemctl start postgresql.service

Hopefully all working now.
I found the postgres log file and it said there was another service using the IP address. I went to the ‘Windows’ solution and did a hard reboot.
All good - thankyou.!

1 Like