The original version of this document is located at https://docs.qfield.org/how-to/project-setup/pg-service
Working with databases simplifies data management in multi-user environments and complex project structures.
QField allows connecting directly to PostgreSQL databases after completing initial configuration steps.
This page provides step-by-step instructions to configure PostgreSQL database connections for QField and QFieldCloud.
QGIS supports two methods to connect to a PostgreSQL database:
We recommend using PG service files for security rather than storing unencrypted database credentials inside project files.
You can create a PostgreSQL connection directly inside QGIS.
Warning
We do not recommend storing database credentials directly in QGIS project files due to data security risks.
Workflow
If you stored access credentials in the Authentication section, QField can edit and digitize features directly.

Connect to PostgreSQL using a service configuration file.
A pg_service.conf file stores parameter definitions to access databases under named service entries.
Using service files avoids storing hostnames, ports, database names, and passwords directly inside QGIS project files.
Service files allow quickly switching between multiple database instances across different projects.
Read more about PostgreSQL service connection files in the QGIS Documentation.
The PG Service Parser Plugin simplifies creating and managing service configuration files in QGIS.
Workflow
🖥️ Desktop preparation
pg_service.conf file in the default directory.
Workflow
🖥️ Desktop preparation

Workflow
🖥️ Desktop preparation
The new connection appears under the PostgreSQL entry in the QGIS Browser panel.
When using a PG service file to connect to PostGIS, you must provide the service configuration file on your mobile device or save it in QFieldCloud as a project secret.
When transferring projects via USB cable, copy your service configuration file directly to the QField application directory on your mobile device.
The QField application directory on Android is located at Android/data/ch.opengis.qfield/files/QField.
Note
.pg_service.conf, Android uses pg_service.conf without a leading dot.QFieldCloud supports pg_service.conf configurations using project secrets.
Set PostgreSQL layers to the Offline editing cloud packaging action and save your service settings on the QFieldCloud project secrets page.
Read more about configuring PostgreSQL service secrets in the QFieldCloud documentation.
pg_service.conf File for PostgreSQL ConnectionsEnsure your PostgreSQL database allows connections from QFieldCloud servers before setting up database access.
Refer to Technical Specifications for server IP requirements.
pg_service.conf FileCreate and populate a service configuration file on your operating system.
Read more in the PostgreSQL Documentation.
pg_service.conf in your user profile or application folder..pg_service.conf in your home directory (~).Define Connection Parameters:
Add your database parameters using the following format:
ini
[SERVICE_NAME]
host=your_host_or_ip
port=your_port
dbname=your_database_name
user=your_username
password=your_password
Replace placeholder values with your actual database parameters and save the file.
Create an environment variable on Windows to ensure QGIS and system tools locate pg_service.conf.
Workflow
PGSERVICEFILEC:\Users\<YourUsername>\AppData\Roaming\postgresql\pg_service.conf (or your custom pg_service.conf file path).
Setting Environment Variables in QGIS:
Workflow
PGSERVICEFILE variable name and file path.
Refer to the QGIS System Settings Documentation for additional details.
Use client certificates to verify user identities when connecting to PostgreSQL servers by defining SSL parameters in pg_service.conf.
ini
[SERVICE_NAME]
host=your_host_or_ip
port=your_port
dbname=your_database_name
user=your_username
password=your_password
sslcert=client.crt
sslkey=client.key
sslrootcert=server.crt
These parameters must point to valid certificate and key files and placed directly alongside your pg_service.conf file within the QField data folder. For more information on this identification method, refer to the PostgreSQL documentation.