# Migrate from sqlite to PostgreSQL

**URL:** <https://discourse.joplinapp.org/t/migrate-from-sqlite-to-postgresql/32574>\
**Category:** Support\
**Created:** [6 September 2023 12:55 UTC](https://discourse.joplinapp.org/t/migrate-from-sqlite-to-postgresql/32574 "2023-09-06T12:55:02Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![tom](https://avatars.discourse-cdn.com/v4/letter/t/3d9bf3/32.png) [@tom](https://discourse.joplinapp.org/u/tom)\
**Post date:** [6 September 2023 12:55 UTC](https://discourse.joplinapp.org/t/migrate-from-sqlite-to-postgresql/32574/1 "2023-09-06T12:55:02Z")

</div>

Hello,

I use Joplin Server as a Docker container and I am very satisfied.

I entered credentials for the postgreSQL-database during the installation, as recommended. However, as the postgreSQL-database hadn't been created, I am sure that this is not used.

I have two questions regarding this:

- How can I switch from SQLite to PostgreSQL?
- And where can I find the SQLite database in my container? I just can't find it

I have many \*.md-files on the server in the "items" folder. Is it possible that I don't use a database at all?

On the other hand I have a "joplin-db-1" (postgres:15) container running within docker. I'm confused...?

Thanks in advance

---

<div class="post-metadata">

**Author:** ![andrewdolphin](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/andrewdolphin/32/17944_2.png) [@andrewdolphin](https://discourse.joplinapp.org/u/andrewdolphin)\
**Post date:** [7 September 2023 19:34 UTC](https://discourse.joplinapp.org/t/migrate-from-sqlite-to-postgresql/32574/2 "2023-09-07T19:34:28Z")

</div>

How exactly did you create the server docker container?

Did you use docker-compose? If so can you copy/paste your compose document here (obfuscating passwords etc)?

---

<div class="post-metadata">

**Author:** ![tom](https://avatars.discourse-cdn.com/v4/letter/t/3d9bf3/32.png) [@tom](https://discourse.joplinapp.org/u/tom)\
**Post date:** [8 September 2023 07:06 UTC](https://discourse.joplinapp.org/t/migrate-from-sqlite-to-postgresql/32574/3 "2023-09-08T07:06:57Z")

</div>

Thanks for the quick reply and sorry for not posting this configuration data from the beginning.

I installed this via a "stacks" in Portainer, via [this](https://noted.lol/install-joplin-server-using-docker-compose/) tutorial with this configuration data:

```auto
version: '3'

services:
    db:
        image: postgres:15
        volumes:
            - /docker/joplindb:/var/lib/postgresql/data
        ports:
            - "5432:5432"
        restart: unless-stopped
        environment:
            - POSTGRES_PASSWORD=postgres
            - POSTGRES_USER=postgres
            - POSTGRES_DB=joplin
    app:
        image: joplin/server:latest
        depends_on:
            - db
        ports:
            - "22300:22300"
        restart: unless-stopped
        environment:
            - APP_PORT=22300
            - APP_BASE_URL=https://websiteurl.com
            - DB_CLIENT=pg
            - POSTGRES_PASSWORD=postgres
            - POSTGRES_DATABASE=joplin
            - POSTGRES_USER=postgres
            - POSTGRES_PORT=5432
            - POSTGRES_HOST=db
            - MAILER_ENABLED=1
            - MAILER_HOST=smtp.gmail.com
            - MAILER_PORT=465
            - MAILER_SECURE=1
            - MAILER_AUTH_USER=youremail@gmail.com
            - MAILER_AUTH_PASSWORD=Y0urP@ssw0rd
            - MAILER_NOREPLY_NAME=Joplin
            - MAILER_NOREPLY_EMAIL=email@email.com
            
volumes:
  joplindb:

```

Joplin Server works now.

I now can see there two containers:

 ![image](https://canada1.discourse-cdn.com/flex028/uploads/cozic/original/3X/9/a/9adc8be42f97f8be4016248687f7cd18dc5cb158.png)

But still I have the impression, that Joplin is not using sqlite/postgreSQL an still is uploading \*md-files to my server:

 ![image](https://canada1.discourse-cdn.com/flex028/uploads/cozic/original/3X/6/9/696aae1941c43a4ad05a901b3afe6cea468687fe.png)

I cannot find a SQLite file on the server, nor a PostgreSQL database (postgre not installed on system, /var/lib/postgresql/data doesn't exist.)

However, if I understood correctly, the database solution is recommended for productive use. Therefore I would like to change this very much and would be very happy about a tip how I can do this.

Thank you so much for your support.

---

<div class="post-metadata">

**Author:** ![andrewdolphin](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/andrewdolphin/32/17944_2.png) [@andrewdolphin](https://discourse.joplinapp.org/u/andrewdolphin)\
**Post date:** [8 September 2023 08:56 UTC](https://discourse.joplinapp.org/t/migrate-from-sqlite-to-postgresql/32574/4 "2023-09-08T08:56:04Z")

</div>

Thanks,

Can you post the logs from the joplin server container? Preferably what happens at start up.

The postgres container logs would be useful also.

That docker compose should be using the postgres database but I suspect you have a volume issue.

Does the directory "/docker/joplindb" exist on your filesystem?

---

<div class="post-metadata">

**Author:** ![tom](https://avatars.discourse-cdn.com/v4/letter/t/3d9bf3/32.png) [@tom](https://discourse.joplinapp.org/u/tom)\
**Post date:** [8 September 2023 10:37 UTC](https://discourse.joplinapp.org/t/migrate-from-sqlite-to-postgresql/32574/5 "2023-09-08T10:37:20Z")

</div>

Thank you so much for your support, I really your help!

Here are the log files:

JoplinDB:

```auto
2023-09-08 10:19:34.286 UTC [1] LOG: received fast shutdown request
2023-09-08 10:19:34.289 UTC [1] LOG: aborting any active transactions
2023-09-08 10:19:34.295 UTC [141] FATAL: terminating connection due to administrator command
2023-09-08 10:19:34.304 UTC [1] LOG: background worker "logical replication launcher" (PID 31) exited with exit code 1
2023-09-08 10:19:34.304 UTC [32] FATAL: terminating connection due to administrator command
2023-09-08 10:19:34.309 UTC [26] LOG: shutting down
2023-09-08 10:19:34.311 UTC [26] LOG: checkpoint starting: shutdown immediate
2023-09-08 10:19:34.320 UTC [26] LOG: checkpoint complete: wrote 2 buffers (0.0%); 0 WAL file(s) added, 0 removed, 0 recycled; write=0.002 s, sync=0.002 s, total=0.011 s; sync files=2, longest=0.002 s, average=0.001 s; distance=5 kB, estimate=78 kB
2023-09-08 10:19:34.326 UTC [1] LOG: database system is shut down
PostgreSQL Database directory appears to contain a database; Skipping initialization
2023-09-08 10:19:36.870 UTC [1] LOG: starting PostgreSQL 15.4 (Debian 15.4-1.pgdg120+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit
2023-09-08 10:19:36.870 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
2023-09-08 10:19:36.870 UTC [1] LOG: listening on IPv6 address "::", port 5432
2023-09-08 10:19:36.873 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2023-09-08 10:19:36.883 UTC [28] LOG: database system was shut down at 2023-09-08 10:19:34 UTC
2023-09-08 10:19:36.892 UTC [1] LOG: database system is ready to accept connections

```

JoplinApp:

```auto
2023-09-08 10:27:13: App: Content driver: { type: 1 }
2023-09-08 10:27:13: App: Content driver (fallback): null
2023-09-08 10:27:13: App: Trying to connect to database...
2023-09-08 10:27:13: App: Connection check: {
  latestMigration: { name: '20221020143305_task_states.js', done: true },
  isCreated: true,
  error: null
}
2023-09-08 10:27:13: App: Auto-migrating database...
2023-09-08 10:27:13: App: Latest migration: { name: '20221020143305_task_states.js', done: true }
2023-09-08 10:27:13: App: Performing main storage check...
2023-09-08 10:27:13: App: Database storage is special and cannot be checked this way. If the connection to the database was successful then the storage driver should work too.
2023-09-08 10:27:13: App: Starting services...
2023-09-08 10:27:13: ShareService: Starting maintenance...
2023-09-08 10:27:13: EmailService: Starting maintenance...
2023-09-08 10:27:13: TaskService: Scheduling #1 (Delete expired tokens): 0 */6 * * *
2023-09-08 10:27:13: TaskService: Scheduling #2 (Update total sizes): 0 * * * *
2023-09-08 10:27:13: TaskService: Scheduling #3 (Process oversized accounts): 30 */2 * * *
2023-09-08 10:27:13: TaskService: Scheduling #6 (Delete expired sessions): 0 */6 * * *
2023-09-08 10:27:13: TaskService: Scheduling #7 (Compress old changes): 0 0 */2 * *
2023-09-08 10:27:13: TaskService: Scheduling #8 (Process user deletions): 10 * * * *
2023-09-08 10:27:13: TaskService: Scheduling #10 (Process orphaned items): 15 * * * *
2023-09-08 10:27:13: App: Call this for testing: `curl https://domain.tld/api/ping`
2023-09-08 10:27:13: ShareService: Maintenance completed in 46ms
2023-09-08 10:27:14: EmailService: Transporter is operational - service will be enabled
2023-09-08 10:27:14: EmailService: Maintenance completed in 238ms

```

When I connect via SSH, I don't see any folder under /docker, or /docker/volumes:

 ![image](https://canada1.discourse-cdn.com/flex028/uploads/cozic/original/3X/1/d/1d508ececd29f3499f3197485888758c6c774ba0.jpeg)

There is also no volume in Portainer:

![image](https://canada1.discourse-cdn.com/flex028/uploads/cozic/original/3X/2/6/26401805ea4b97de539fbcbe733e67b1766a9950.png)

Did I miss something regarding creating a volume during the setup?

Thank you so much in advance!

---

<div class="post-metadata">

**Author:** ![tom](https://avatars.discourse-cdn.com/v4/letter/t/3d9bf3/32.png) [@tom](https://discourse.joplinapp.org/u/tom)\
**Post date:** [8 September 2023 15:23 UTC](https://discourse.joplinapp.org/t/migrate-from-sqlite-to-postgresql/32574/6 "2023-09-08T15:23:33Z")

</div>

What I recignized:

> [@tom](#):
>
> `starting PostgreSQL 15.4 (Debian 15.4-1.pgdg120+1) on x86_64-pc-linux-gnu`

Ist it relevant that I'm using Ubuntu? Why does it say Debian?

Also: I've created a volume called "joplindb"...not sure yet if that's necessary 🙂 but the stack-code seems tor require it?

---

<div class="post-metadata">

**Author:** ![andrewdolphin](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/andrewdolphin/32/17944_2.png) [@andrewdolphin](https://discourse.joplinapp.org/u/andrewdolphin)\
**Post date:** [8 September 2023 19:21 UTC](https://discourse.joplinapp.org/t/migrate-from-sqlite-to-postgresql/32574/7 "2023-09-08T19:21:58Z")

</div>

You're mounting the database location to /docker/joplindb, that would be a docker directory in your root directory on your local filesystem, is there anything there?

The volume section in your compose file isn't needed as you are mounting to the above location and not an alias.

---

<div class="post-metadata">

**Author:** ![tom](https://avatars.discourse-cdn.com/v4/letter/t/3d9bf3/32.png) [@tom](https://discourse.joplinapp.org/u/tom)\
**Post date:** [8 September 2023 20:05 UTC](https://discourse.joplinapp.org/t/migrate-from-sqlite-to-postgresql/32574/8 "2023-09-08T20:05:25Z")

</div>

Oh yes! There is such a folder! 🙂

I was always looking in /var/lib/docker

Does that mean, that I'm currently using postgresql? I'm wondering, as I haven't created a database at thr beginning?

So there is no necessity to create that volume?

---

<div class="post-metadata">

**Author:** ![tom](https://avatars.discourse-cdn.com/v4/letter/t/3d9bf3/32.png) [@tom](https://discourse.joplinapp.org/u/tom)\
**Post date:** [10 September 2023 11:35 UTC](https://discourse.joplinapp.org/t/migrate-from-sqlite-to-postgresql/32574/9 "2023-09-10T11:35:40Z")

</div>

The thing that I don't understand is:

- why do I have so many \*.md files to be found via the web interface? These files should be in the postgresql-database, shouldn't they?
- that I am not able to do a database-backup via console. How do you guys do that?

Thanks!

---

<div class="post-metadata">

**Author:** ![dpoulton](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/dpoulton/32/29723_2.png) [@dpoulton](https://discourse.joplinapp.org/u/dpoulton)\
**Post date:** [10 September 2023 22:06 UTC](https://discourse.joplinapp.org/t/migrate-from-sqlite-to-postgresql/32574/10 "2023-09-10T22:06:23Z")

</div>

> [@tom](#):
>
> why do I have so many \*.md files to be found via the web interface? These files should be in the postgresql-database, shouldn't they?

You are using the admin account as your sync account. I believe that only the admin account has an _items_ view and what it is showing are the sync files stored in your Postgresql database.

---

<div class="post-metadata">

**Author:** ![tom](https://avatars.discourse-cdn.com/v4/letter/t/3d9bf3/32.png) [@tom](https://discourse.joplinapp.org/u/tom)\
**Post date:** [11 September 2023 10:00 UTC](https://discourse.joplinapp.org/t/migrate-from-sqlite-to-postgresql/32574/11 "2023-09-11T10:00:43Z")

</div>

Thank you so much, that makes sense!

I would like to make a backup of the PostgreSQL database. I was thankfully tipped here in the thread where to find the database folder:

/docker/joplindb

However, I am not sure how to backup the database. Is it enough to backup the folder?

Do you have a hint for me?

---

<div class="post-metadata">

**Author:** ![andrewdolphin](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/andrewdolphin/32/17944_2.png) [@andrewdolphin](https://discourse.joplinapp.org/u/andrewdolphin)\
**Post date:** [11 September 2023 12:35 UTC](https://discourse.joplinapp.org/t/migrate-from-sqlite-to-postgresql/32574/12 "2023-09-11T12:35:25Z")

</div>

You have a few options but backing up the folder is one of them yes.

> **[Chapter 26. Backup and Restore](https://www.postgresql.org/docs/current/backup.html)**
>
> Chapter 26. Backup and Restore Table of Contents 26.1. SQL Dump 26.1.1. Restoring the Dump 26.1.2. Using pg\_dumpall 26.1.3. Handling Large Databases …

---

<div class="post-metadata">

**Author:** ![tom](https://avatars.discourse-cdn.com/v4/letter/t/3d9bf3/32.png) [@tom](https://discourse.joplinapp.org/u/tom)\
**Post date:** [11 September 2023 15:28 UTC](https://discourse.joplinapp.org/t/migrate-from-sqlite-to-postgresql/32574/13 "2023-09-11T15:28:00Z")

</div>

Thanks a lot!

Something strange that caught my eye:

I changed the name of the folder "joplindb" and still everything works and the data is accessible and it synchronizes.

Somehow I'm still not really convinced that I'm using the right database...

That, hopefully, is my last question. Thanks a lot in advance!

---

<div class="post-metadata">

**Author:** ![apj68](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/apj68/32/16053_2.png) [@apj68](https://discourse.joplinapp.org/u/apj68)\
**Post date:** [12 September 2023 15:26 UTC](https://discourse.joplinapp.org/t/migrate-from-sqlite-to-postgresql/32574/14 "2023-09-12T15:26:07Z")

</div>

Have you tried using the postgres credentials and trying to logon and poke around?

---

<div class="post-metadata">

**Author:** ![tom](https://avatars.discourse-cdn.com/v4/letter/t/3d9bf3/32.png) [@tom](https://discourse.joplinapp.org/u/tom)\
**Post date:** [12 September 2023 18:57 UTC](https://discourse.joplinapp.org/t/migrate-from-sqlite-to-postgresql/32574/15 "2023-09-12T18:57:05Z")

</div>

What do you mean by that? Where should I use the postgre-credentials?

---

<div class="post-metadata">

**Author:** ![apj68](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/apj68/32/16053_2.png) [@apj68](https://discourse.joplinapp.org/u/apj68)\
**Post date:** [13 September 2023 00:26 UTC](https://discourse.joplinapp.org/t/migrate-from-sqlite-to-postgresql/32574/16 "2023-09-13T00:26:22Z")

</div>

It seems that you ought to be able to use any database client to connect to your database and check around the tables and whatnot to see if you can validate/invalidate your theory that the db is not being used. Note that I've not done this, I'm just another Joe User like yourself but from your logs it does appear that the database is being started so provided it's not encrypted I'm guessing you can logon to it.

---

<div class="post-metadata">

**Author:** ![tom](https://avatars.discourse-cdn.com/v4/letter/t/3d9bf3/32.png) [@tom](https://discourse.joplinapp.org/u/tom)\
**Post date:** [15 September 2023 08:19 UTC](https://discourse.joplinapp.org/t/migrate-from-sqlite-to-postgresql/32574/17 "2023-09-15T08:19:53Z")

</div>

Sorry, but I still don't understand this properly ☹

I can change the PostgreSQL folder and still log in completely and also use Joplin via the apps.

Does this mean that the database path doesn't seem to be used at all?

Likewise, I can't reach the database via shell, so I can't make a backup. How can that be?

Or is it really enough that I simply save the folder as a ZIP file and then have a working backup?

---

<div class="post-metadata">

**Author:** ![kja999](https://avatars.discourse-cdn.com/v4/letter/k/eb8c5e/32.png) [@kja999](https://discourse.joplinapp.org/u/kja999)\
**Post date:** [15 September 2023 12:59 UTC](https://discourse.joplinapp.org/t/migrate-from-sqlite-to-postgresql/32574/18 "2023-09-15T12:59:02Z")

</div>

as you have docker already, use the pgAdmin4 docker image, it's a tool for postgres db admin.  
details here: [Container Deployment — pgAdmin 4 7.6 documentation](https://www.pgadmin.org/docs/pgadmin4/latest/container_deployment.html)

After launching it (it creates a web admin page), add a server connection to your joplin database using the server db credentials in your original docker command for the db.  
Then you can browse the database and see what its up to...

(it also helps you run the backups)

Hint: In portainer I added the pgAdmin docker container to the joplin server db network so they could talk easier...

EDIT: I should add.. messing around in there potentially is dangerous to your data ... be careful

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex028/uploads/cozic/original/3X/1/c/1c948e33314e232a0927789508474d8624f4270b.png) [@system](https://discourse.joplinapp.org/u/system)\
**Post date:** [15 October 2023 12:59 UTC](https://discourse.joplinapp.org/t/migrate-from-sqlite-to-postgresql/32574/19 "2023-10-15T12:59:17Z")

</div>

Closed on 15 October 2023 12:59 UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
