PostgreSQL servicio¶
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.
Lea más sobre los servicios de PostgreSQL en la documentación de QGIS.
QField - Conexión directa¶
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.
Por lo general, la ruta en los dispositivos Android se ve así: /Android/data/ch.opengis.qfield/files/QField
.
Nota
A diferencia de los sistemas *NIX donde el archivo se llama .pg_service.conf
, el archivo en Android se llama pg_service.conf
sin el signo de punto inicial (.
).
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.
Lea más cómo configurar el servicio PostgreSQL en la documentación de QFieldCloud.
Creación de un archivo pg_service.conf
para la conexión PostgreSQL en QGIS y Secrets¶
Before beginning, ensure that your PostgreSQL database allows connections from QFieldCloud. Refer to Technical specs for instructions.
Configurar el archivo pg_service.conf
.¶
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.
-
Crear un archivo de configuración:
-
En Windows: Cree un archivo llamado
pg_service.conf
y guárdelo en una ubicación conveniente. -
En Linux/MacOS/Unix: Cree un archivo llamado
.pg_service.conf
en su carpeta de inicio (~
). -
Definir parámetros de conexión:
Dentro del archivo, especifique los parámetros de conexión para su base de datos PostgreSQL utilizando el siguiente formato:
[SERVICE_NAME]
host=your_host_or_ip
port=your_port
dbname=your_database_name
user=your_username
password=your_password
Sustituya los marcadores de posición (tu_host_o_ip
, tu_puerto
, tu_nombre_basedatos
, tu_nombreusuario
, tu_contraseña
) por los detalles reales de la conexión y guarde el archivo.
Pasos adicionales de configuración para Windows¶
-
Establecer variable de entorno: Para asegurarse de que QGIS reconoce
pg_service.conf
, cree una variable de entorno que apunte a su ubicación: -
Vaya a "Este PC" o "Mi PC" > Propiedades > Configuración avanzada del sistema > Variables de entorno.
- Añadir una variable nueva:
- Nombre de la variable:
PGSERVICEFILE
- Valor variable:
C:\Users\<YourUsername>\AppData\Roaming\postgresql\pg_service.conf
(or yourpg_service.conf
file path).
- Nombre de la variable:
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. -
Abrir QGIS.
- Vaya a "Capa" > "Añadir capa" > "Añadir capas PostGIS...".
- En "Crear una nueva conexión PostGIS", seleccione "Servicio" en el menú desplegable.
- Introduzca el nombre del servicio de
pg_service.conf
(por ejemplo,[NINJA_DB]
) en el campo "Service". - Haga clic en "Aceptar" para conectarse a su base de datos PostgreSQL utilizando las configuraciones de
pg_service.conf
.
- 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.