# New Addon: SQL Driver for Cockpit

**URL:** <https://discourse.getcockpit.com/t/new-addon-sql-driver-for-cockpit/1029>\
**Category:** Addons\
**Created:** [September 16, 2019, 2:08pm UTC](https://discourse.getcockpit.com/t/new-addon-sql-driver-for-cockpit/1029 "2019-09-16T14:08:33Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![piotr-cz](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/piotr-cz/32/425_2.png) [@piotr-cz](https://discourse.getcockpit.com/u/piotr-cz)\
**Post date:** [September 16, 2019, 2:08pm UTC](https://discourse.getcockpit.com/t/new-addon-sql-driver-for-cockpit/1029/1 "2019-09-16T14:08:34Z")

</div>

This addon allows to use MySQL/ MariaDB/ PostgreSQL databases instead of default Mongo/ SQLite.

## Requirements

- Cockpit CMS (next or legacy)
- MySQL 5.7.9/ MariaDB 10.2.6/ PostgreSQL 9.4
- PHP 7.1
- Enabled PHP extensions: pdo, pdo\_mysql/ pdo\_pgsql

> **[piotr-cz/cockpit-sql-driver](https://github.com/piotr-cz/cockpit-sql-driver)**
>
> SQL Driver for Cockpit CMS. Contribute to piotr-cz/cockpit-sql-driver development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![artur](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/artur/32/4_2.png) [@artur](https://discourse.getcockpit.com/u/artur)\
**Post date:** [September 16, 2019, 8:05pm UTC](https://discourse.getcockpit.com/t/new-addon-sql-driver-for-cockpit/1029/2 "2019-09-16T20:05:24Z")

</div>

👀 thank you for making this effort!

---

<div class="post-metadata">

**Author:** ![serjoscha87](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/serjoscha87/32/151_2.png) [@serjoscha87](https://discourse.getcockpit.com/u/serjoscha87)\
**Post date:** [September 18, 2019, 5:47pm UTC](https://discourse.getcockpit.com/t/new-addon-sql-driver-for-cockpit/1029/3 "2019-09-18T17:47:10Z")

</div>

This is great! I added it to the addon list 🙂

---

<div class="post-metadata">

**Author:** ![WillyBrown](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/willybrown/32/454_2.png) [@WillyBrown](https://discourse.getcockpit.com/u/WillyBrown)\
**Post date:** [February 6, 2020, 12:19am UTC](https://discourse.getcockpit.com/t/new-addon-sql-driver-for-cockpit/1029/4 "2020-02-06T00:19:28Z")

</div>

Thanks @piotr-cz!  
Is this solution has been tested in large application context? I’m in project case Sqlite seems to be too light solution and client server does not allow mongodb usage.

---

<div class="post-metadata">

**Author:** ![piotr-cz](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/piotr-cz/32/425_2.png) [@piotr-cz](https://discourse.getcockpit.com/u/piotr-cz)\
**Post date:** [February 7, 2020, 7:47pm UTC](https://discourse.getcockpit.com/t/new-addon-sql-driver-for-cockpit/1029/5 "2020-02-07T19:47:16Z")

</div>

Honestly no, it hasn’t been tested on large databases on production.  
My goal was to get access to database for 3p services and SQL tools when developing locally.

In my short testing I just found that for example MySQL/ PostgreSQL is slower that SQLite, but that’s not surprise as it’s basically file access vs database server connection.

However you may and should perform some database optimisations (as described here [https://github.com/piotr-cz/cockpit-sql-driver#manual-database-optimisations](https://github.com/piotr-cz/cockpit-sql-driver#manual-database-optimisations)) like for example adding indexes to columns that are usually searched trough.

---

<div class="post-metadata">

**Author:** ![WillyBrown](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/willybrown/32/454_2.png) [@WillyBrown](https://discourse.getcockpit.com/u/WillyBrown)\
**Post date:** [February 10, 2020, 2:22pm UTC](https://discourse.getcockpit.com/t/new-addon-sql-driver-for-cockpit/1029/6 "2020-02-10T14:22:31Z")

</div>

Thanks a lot, I gonna test it.

---

<div class="post-metadata">

**Author:** ![piotr-cz](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/piotr-cz/32/425_2.png) [@piotr-cz](https://discourse.getcockpit.com/u/piotr-cz)\
**Post date:** [February 10, 2020, 3:04pm UTC](https://discourse.getcockpit.com/t/new-addon-sql-driver-for-cockpit/1029/7 "2020-02-10T15:04:35Z")

</div>

I’ve prepared simple script for performance tests: [https://github.com/piotr-cz/cockpit-sql-driver/blob/master/stress-tests.php](https://github.com/piotr-cz/cockpit-sql-driver/blob/master/stress-tests.php)

It measures time to retrieve all items from all collections in database and there’s an option to pass path to custom config file.

I’d imagine that the MySQL/ PostgreSQL with column indexes would outperform SQLite when using large datasets and retrieving results with conditions or sorting.

The difference is that Cockpit’s SQLite driver executes compiled php function on every row, while this SQL Driver uses MySQL/ PostgreSQL statements.

---

<div class="post-metadata">

**Author:** ![piotr-cz](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/piotr-cz/32/425_2.png) [@piotr-cz](https://discourse.getcockpit.com/u/piotr-cz)\
**Post date:** [February 21, 2020, 1:07pm UTC](https://discourse.getcockpit.com/t/new-addon-sql-driver-for-cockpit/1029/8 "2020-02-21T13:07:06Z")

</div>

Is anyone out there using this addon in production?

If so, I’m interested in you experiences (possible problems, performance, and so on).

---

<div class="post-metadata">

**Author:** ![piotr-cz](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/piotr-cz/32/425_2.png) [@piotr-cz](https://discourse.getcockpit.com/u/piotr-cz)\
**Post date:** [February 24, 2020, 8:33am UTC](https://discourse.getcockpit.com/t/new-addon-sql-driver-for-cockpit/1029/9 "2020-02-24T08:33:05Z")

</div>

I’ve just released [v1.0.0-beta.2](https://github.com/piotr-cz/cockpit-sql-driver/releases/tag/v1.0.0-beta.2) which fixes compatibility with Cockpit v0.9.3+.  
See related [Issue](https://github.com/piotr-cz/cockpit-sql-driver/issues/1).

Problem occurs when deleting (moving to trash) entries in Cockpit v0.9.3.

Please be warned that as at this moment Cockpit doesn’t have public API for storage drivers, this addon may become dysfunctional whenever storage API changes in future Cockpit releases.

---

<div class="post-metadata">

**Author:** ![xJoeyv](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/xjoeyv/32/116_2.png) [@xJoeyv](https://discourse.getcockpit.com/u/xJoeyv)\
**Post date:** [March 30, 2020, 9:27pm UTC](https://discourse.getcockpit.com/t/new-addon-sql-driver-for-cockpit/1029/10 "2020-03-30T21:27:11Z")

</div>

I will be using it in production. Settin up a new site atm using Cockpit and this driver

---

<div class="post-metadata">

**Author:** ![xJoeyv](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/xjoeyv/32/116_2.png) [@xJoeyv](https://discourse.getcockpit.com/u/xJoeyv)\
**Post date:** [March 30, 2020, 9:43pm UTC](https://discourse.getcockpit.com/t/new-addon-sql-driver-for-cockpit/1029/11 "2020-03-30T21:43:29Z")

</div>

Sadly my version is not supported and my choice of DB.

```
Driver requires database server version >= 10.2.6, got 10.1.44-MariaDB-0ubuntu0.18.04.1
```

---

<div class="post-metadata">

**Author:** ![piotr-cz](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/piotr-cz/32/425_2.png) [@piotr-cz](https://discourse.getcockpit.com/u/piotr-cz)\
**Post date:** [March 31, 2020, 7:45am UTC](https://discourse.getcockpit.com/t/new-addon-sql-driver-for-cockpit/1029/12 "2020-03-31T07:45:41Z")

</div>

Unfortunately too many shared hosting providers are still on old database versions.  
For example MySQL 5.6.x which has been released with feature set as of 2013.

---

<div class="post-metadata">

**Author:** ![BklnMark](https://avatars.discourse-cdn.com/v4/letter/b/e9bcb4/32.png) [@BklnMark](https://discourse.getcockpit.com/u/BklnMark)\
**Post date:** [May 7, 2020, 7:14am UTC](https://discourse.getcockpit.com/t/new-addon-sql-driver-for-cockpit/1029/13 "2020-05-07T07:14:17Z")

</div>

Can this project use couchbase instead of mongodb?

---

<div class="post-metadata">

**Author:** ![piotr-cz](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/piotr-cz/32/425_2.png) [@piotr-cz](https://discourse.getcockpit.com/u/piotr-cz)\
**Post date:** [May 7, 2020, 8:30am UTC](https://discourse.getcockpit.com/t/new-addon-sql-driver-for-cockpit/1029/14 "2020-05-07T08:30:14Z")

</div>

Sorry, I don’t have experience with Couchbase.  
At this moment addon uses php PDO extensions which doesn’t support Couchbase.

It’s possible to prepare a Couchbase driver, however it would take some effort as some of the PDO features would have to be ported.

---

<div class="post-metadata">

**Author:** ![artur](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/artur/32/4_2.png) [@artur](https://discourse.getcockpit.com/u/artur)\
**Post date:** [May 7, 2020, 7:10pm UTC](https://discourse.getcockpit.com/t/new-addon-sql-driver-for-cockpit/1029/15 "2020-05-07T19:10:10Z")

</div>

no, couchbase is not supported.

---

<div class="post-metadata">

**Author:** ![wlfnkls](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/wlfnkls/32/655_2.png) [@wlfnkls](https://discourse.getcockpit.com/u/wlfnkls)\
**Post date:** [July 2, 2020, 8:06pm UTC](https://discourse.getcockpit.com/t/new-addon-sql-driver-for-cockpit/1029/16 "2020-07-02T20:06:26Z")

</div>

Hey,

I just configured cockpit to use your addon, thanks for this!

So far it works great, but I ran into a problem:  
when I try to upload an image to the assets section, the file is not uploaded.  
When the assets section is refreshed I can see an entry, but its corrupt (no meta, no image).

I checked the issues on github but didnt find any hint.

Do you have an idea?

Thanks!

---

<div class="post-metadata">

**Author:** ![piotr-cz](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/piotr-cz/32/425_2.png) [@piotr-cz](https://discourse.getcockpit.com/u/piotr-cz)\
**Post date:** [July 15, 2020, 10:43am UTC](https://discourse.getcockpit.com/t/new-addon-sql-driver-for-cockpit/1029/17 "2020-07-15T10:43:40Z")

</div>

Hi,  
Thanks for reporting, there was a bug that prevented storing correctly asset entries in database.  
I’m not using assets in Cockpit so this passed my manual tests.

New version [v1.0.0-rc.2](https://github.com/piotr-cz/cockpit-sql-driver/releases/tag/v1.0.0-rc.2) contains bugifx.

If you encounter any errors on the Cockpit assets page (check DevTools console) or any other strange behavior related to assets, it may be necessary to remove asset entries manually from database:

- look up the `cockpit/assets` table in database editor and remove all entries
- you may also remove uploaded files in `COCKPIT_STORAGE_FOLDER/uploads/`
