How to fix FATAL: data directory has invalid permissions in PostgreSQL

PostgreSQLINTERMEDIATEHIGHUpdated Dec 26, 2025ยท 384 views

PostgreSQL requires the data directory to have restrictive permissions (0700 or 0750). This error appears when permissions are too permissive, typically after pod restarts in containers or when mounting volumes with incorrect ownership.

Quick fix

Fixes FATAL: data directory has invalid permissions

ls -ld /var/lib/postgresql/data
  1. Check current permissions on the data directory
  2. Check directory ownership
  3. Fix permissions if they are too permissive
  4. Fix ownership if needed
postgresql โ€” error
ls -ld /var/lib/postgresql/data
FATAL: data directory has invalid permissions

What this error means

PostgreSQL enforces strict security requirements on its data directory to prevent unauthorized access to sensitive database files. When PostgreSQL starts, it verifies that the data directory has permissions set to 0700 (rwx------) or 0750 (rwxr-x---), meaning only the PostgreSQL system user can read, write, and execute. If the directory has broader permissions (group or world access), PostgreSQL refuses to start. This typically occurs in containerized environments (Docker, Kubernetes) where volume mounts, init containers, or permission changes during pod restarts result in incorrect file ownership or permissions.

Typical symptoms

  • PostgreSQL container or pod fails to start
  • Error message shows "Permissions should be u=rwx (0700) or u=rwx,g=rx (0750)"
  • Application cannot connect to PostgreSQL database
  • Kubernetes pod stuck in CrashLoopBackOff state
  • Docker container exits immediately after starting
  • Helm chart deployment fails during pod initialization

Common causes

  1. Volume mounted with incorrect permissions from host filesystem
  2. Init container missing or removed that should chmod the data directory
  3. Directory has mode 755, 760, or other permissions wider than 750
  4. Pod restart with existing data directory that wasn't properly initialized
  5. Windows Docker Desktop (Hyper-V) mounting volumes with default Windows permissions
  6. Kubernetes persistent volume claim (PVC) mounted with incorrect permissions
  7. File ownership changed to non-PostgreSQL user during container lifecycle

How to fix "FATAL: data directory has invalid permissions"

1Check current permissions on the data directory

Connect to your container or server and check the actual permissions:

bash
ls -ld /var/lib/postgresql/data

You'll see output like drwx------ (0700) which is correct, or drwxr-xr-x (0755) which is wrong. The directory should show only the first three permission bits set (owner rwx only).

2Check directory ownership

Verify the data directory is owned by the PostgreSQL system user:

bash
ls -ld /var/lib/postgresql/data

The output should show ownership by the postgres user (or equivalent PostgreSQL user). If it's owned by root or another user, this is the problem.

3Fix permissions if they are too permissive

If the permissions are not 0700 or 0750, fix them with:

bash
chmod 700 /var/lib/postgresql/data

For Docker containers, you may need to run this as root or with sudo. For Kubernetes, add this to your init container.

4Fix ownership if needed

If the directory is owned by the wrong user, change ownership to the PostgreSQL user:

bash
chown postgres:postgres /var/lib/postgresql/data

On some systems, the PostgreSQL user may be named differently (check /etc/passwd for the correct name).

5For Docker: Add chmod step in init container

In your Dockerfile or docker-compose.yml, add a step that ensures correct permissions before PostgreSQL starts:

yaml
services:
  postgres:
    image: postgres:15
    volumes:
      - postgres_data:/var/lib/postgresql/data
    entrypoint: |
      bash -c "
      chmod 700 /var/lib/postgresql/data
      docker-entrypoint.sh postgres"

Alternatively, use an init container in Kubernetes (see next step).

6For Kubernetes: Add init container to fix permissions

Add an init container to your Kubernetes StatefulSet or Pod that sets correct permissions:

yaml
initContainers:
- name: init-chmod-data
  image: busybox:1.28
  command:
  - sh
  - -c
  - chmod 700 /var/lib/postgresql/data || true
  volumeMounts:
  - name: postgres-data
    mountPath: /var/lib/postgresql/data

This runs before the PostgreSQL container starts and ensures permissions are correct even if the volume was mounted with wrong permissions.

Advanced notes

PostgreSQL requires 0700 or 0750 permissions as a security measure to prevent unauthorized access to sensitive database files like pg_hba.conf (authentication) and shared memory buffers. The 0750 permission (rwxr-x---) allows the PostgreSQL group to read the directory, which is useful in some enterprise setups but 0700 (rwx------) is more restrictive and recommended. In Windows Docker Desktop with Hyper-V backend, permissions issues are especially common because Windows doesn't have the same Unix permission model. WSL backend (Windows Subsystem for Linux) typically handles this better. For Azure Container Instances and managed cloud databases, the data directory is usually on shared storage that doesn't support Unix permissions; use a subdirectory (PGDATA subdirectory) where PostgreSQL has write access instead.

Frequently asked questions

What does "FATAL: data directory has invalid permissions" mean?
PostgreSQL enforces strict security requirements on its data directory to prevent unauthorized access to sensitive database files. When PostgreSQL starts, it verifies that the data directory has permissions set to 0700 (rwx------) or 0750 (rwxr-x---), meaning only the PostgreSQL system user can read, write, and execute. If the directory has broader permissions (group or world access), PostgreSQL refuses to start.
How do I fix "FATAL: data directory has invalid permissions"?
PostgreSQL requires the data directory to have restrictive permissions (0700 or 0750). This error appears when permissions are too permissive, typically after pod restarts in containers or when mounting volumes with incorrect ownership.
What causes "FATAL: data directory has invalid permissions"?
Volume mounted with incorrect permissions from host filesystem Init container missing or removed that should chmod the data directory Directory has mode 755, 760, or other permissions wider than 750
Is the "FATAL: data directory has invalid permissions" error serious?
Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.

Official resources & further reading