PostgreSQL Service¶
A pg_service.conf
file allows to use an named alias for a PostgreSQL server connection.
Instead of storing hostname, port, database name and more into the QGIS Project file, these can be stored separately.
It is even possible to store username and password in a pg_service.conf
file, to avoid having this stored in clear text in the QGIS Project.
Lesen Sie mehr über PostgreSQL-Dienste in der QGIS-Dokumentation.
QField - Direkte Verbindung¶
If you directly connect from QGIS to your database you can make use of a pg_service.conf
file by placing it in the QField data folder.
You can place your file either on the Internal Device Storage or on the SD Card Storage.
You can check the path for the QField data folder in the bottom of the About QField
screen in the app.
Normalerweise sieht der Pfad auf Android-Geräten in etwa so aus:
/Android/data/ch.opengis.qfield/files/QField
Anmerkung
Anders als auf *NIX-Systemen, bei denen die Datei .pg_service.conf
benannt ist, wird die Datei auf Android pg_service.conf
ohne führendes Punktzeichen (.
) benannt.
QFieldCloud¶
QFieldCloud support pg_service.conf
configurations too.
You need to configure your PostgreSQL layers with "Offline editing" cloud action and store your service settings on QFieldCloud Project's Secrets page.
Lesen Sie mehr darüber, wie Sie den PostgreSQL-Dienst konfigurieren in der QFieldCloud-Dokumentation.
Erstellen einer pg_service.conf
Datei für eine PostgreSQL-Verbindung in QGIS und Secrets¶
Before beginning, ensure that your PostgreSQL database allows connections from QFieldCloud. Refer to Technical specs for instructions.
Setup pg_service.conf
Datei¶
We first need to set up a configuration file. There are many options to organize this, read more in the PostgreSQL documentation or follow the description below.
-
Erstellen Sie eine Konfigurationsdatei:
-
Unter Windows: Erstellen Sie eine Datei mit dem Namen
pg_service.conf
und speichern Sie diese an einem geeigneten Ort. -
Unter Linux/MacOS/Unix: Erstellen Sie eine Datei mit dem Namen
.pg_service.conf
in Ihrem Benutzerordner (~
). -
Verbindungsparameter definieren:
Geben Sie in der Datei die Verbindungsparameter für Ihre PostgreSQL-Datenbank im folgenden Format an:
[SERVICE_NAME]
host=your_host_or_ip
port=your_port
dbname=your_database_name
user=your_username
password=your_password
Ersetzen Sie die Platzhalter (your_host_or_ip
, your_port
, your_database_name
, your_username
, your_password
) durch die tatsächlichen Verbindungsdetails und speichern Sie die Datei.
Zusätzliche Konfigurationsschritte für Windows¶
-
Umgebungsvariable setzen: Um sicherzustellen, dass QGIS die
pg_service.conf
Datei erkennt, erstellen Sie eine Umgebungsvariable, die auf ihren Speicherort zeigt -
Navigieren Sie zu "Dieser PC" oder "Arbeitsplatz" > Eigenschaften > Erweiterte Systemeinstellungen > Umgebungsvariablen.
- Fügen Sie eine neue Variable hinzu:
- Variablen-Name:
PGSERVICEFILE
- Variablen-Wert:
C:\Users\<YourUsername>\AppData\Roaming\postgresql\pg_service.conf
(oder Ihrpg_service.conf
Dateipfad).
- Variablen-Name:
Alternatively, you can set environment variables directly in QGIS via Settings > Options > System > Environment. Refer to QGIS System Settings for details.
-
Test the Connection in QGIS: Open QGIS and set up a new PostgreSQL connection using the service name defined in
pg_service.conf
(e.g.,[MY_QGIS_DB]
) in the connection details. QGIS will read configuration frompg_service.conf
automatically. -
Öffnen Sie QGIS.
- Navigieren Sie zu "Layer" > " Layer hinzufügen" > "PostGIS Layer hinzufügen..."
- Wählen Sie unter "Neue PostGIS-Verbindung erstellen" die Option "Service" aus dem Dropdown-Menü aus.
- Geben Sie den Dienstnamen aus der
pg_service.conf
Datei (z. B.[NINJA_DB]
) in das Feld "Dienst" ein. - Klicken Sie auf "OK", um eine Verbindung zu Ihrer PostgreSQL-Datenbank herzustellen, indem Sie die Konfigurationen aus der
pg_service.conf
Datei verwenden.
- Add Parameter to QFieldCloud Secrets: Navigate to the project's secrets page and copy the service directly from
.pg_service.conf
to the secret. Follow Secrets for guidance.