5

How can I export connections in pgadmin4?

I intend to us pgadmin in docker and I want to map the servers.json as suggested. So I thought to simply export my connections in a local pgadmin4 and map them.

I found an explanation to export servers. Unfortunately this does not work. I tried ubuntu 18.04 LTS and Windows 10 Pro but I always end up with error messages. Here is the message I retrieve in ubuntu:

$ python3 /usr/share/pgadmin4/web/setup.py --dump-servers output_file.json
Traceback (most recent call last):
  File "/usr/share/pgadmin4/web/setup.py", line 406, in <module>
    dump_servers(args)
  File "/usr/share/pgadmin4/web/setup.py", line 63, in dump_servers
    app = create_app()
  File "/usr/share/pgadmin4/web/pgadmin/__init__.py", line 229, in create_app
    create_app_data_directory(config)
  File "/usr/share/pgadmin4/web/pgadmin/setup/data_directory.py", line 29, in create_app_data_directory
    _create_directory_if_not_exists(config.SESSION_DB_PATH)
  File "/usr/share/pgadmin4/web/pgadmin/setup/data_directory.py", line 15, in _create_directory_if_not_exists
    os.mkdir(_path)
FileNotFoundError: [Errno 2] No such file or directory: '/var/cache/pgadmin/sessions'

This seems logical, since there is no such file. But how can I export my server settings and share them via servers.json?

2 Answers2

5

JSON format is specified in pgAdmin docs here.

I have pgAdmin running in docker container so following steps helped me to obtain correct server list in JSON format from it. But first I started image with pgAdmin and created all connections via pgAdmin GUI normally.

To export servers.json from docker image.

  1. Get running container id with command:

docker ps

  1. Generate servers.json file with needed servers. As I have not used default user then I needed to specify user too like docker exec -it 3a1adbf57bd9 /venv/bin/python setup.py --dump-servers /tmp/servers.json --user admin.

docker exec -it <container id> /venv/bin/python setup.py --dump-servers /tmp/servers.json

  1. Copy generated file to local disk:

docker cp <container id>:/tmp/servers.json c:\myFolder

adrock20
  • 175
  • 1
  • 7
Aldis
  • 439
  • 4
  • 10
0

You need to map the path for the output_file.json file to your,

For example, To preload the server pre-loaded from /tmp/servers.json on the host:

docker pull dpage/pgadmin4
docker run -p 443:443 \
    -v "/private/var/lib/pgadmin:/var/lib/pgadmin" \
    -v "/tmp/servers.json:/servers.json" \
    -e "PGADMIN_DEFAULT_EMAIL=user@domain.com" \
    -e "PGADMIN_DEFAULT_PASSWORD=SuperSecret" \
    -d dpage/pgadmin4
Murtuza Z
  • 5,639
  • 1
  • 28
  • 52
  • I know that I need to map this file. The thing is not to map it but to get it! I created a connection and I want to export it, but this does not work as described in the documentation (as I said above). So, I do not have a servers.json file that I could map. My question is: how can I export one. – Alfred Pontiac Mar 14 '19 at 10:14