Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read-only mode #34

Closed
hiyelbaz opened this issue Dec 2, 2020 · 5 comments
Closed

Read-only mode #34

hiyelbaz opened this issue Dec 2, 2020 · 5 comments

Comments

@hiyelbaz
Copy link

hiyelbaz commented Dec 2, 2020

Is it possible to connect sqlite in read-only mode?

@hrkuma
Copy link
Contributor

hrkuma commented Dec 3, 2020

Hi,

It is possible to connect sqlite using read-only database file.
I could execute following sequence.
Does this answer your question?

$ sqlite3 /tmp/test.db
sqlite> CREATE TABLE t1(a int primary key, b text);
sqlite> INSERT INTO t1 VALUES (0, 'test');
sqlite> SELECT * FROM t1;
0|test
sqlite>.q
$ chmod a-w /tmp/test.db
$ psql
# CREATE EXTENSION sqlite_fdw;
# CREATE SERVER sqlite_testdb FOREIGN DATA WRAPPER sqlite_fdw OPTIONS (database '/tmp/test.db');
# IMPORT FOREIGN SCHEMA public FROM SERVER sqlite_testdb INTO public;
# SELECT * FROM t1;
SELECT * FROM t1;
 a |  b
---+------
 0 | test
(1 row)
# INSERT INTO t1 VALUES (1, 'new');
INSERT INTO t1 VALUES (1, 'new');
ERROR:  failed to execute remote SQL: rc=8 attempt to write a readonly database
   sql=INSERT INTO main."t1"(`a`, `b`) VALUES (?, ?)

@hiyelbaz
Copy link
Author

hiyelbaz commented Dec 3, 2020

Thanks for the answer. there is a second process writing to sqlite db. As long as they can work together by just setting up file permissions this the solution. I think I need to remove write permission only from postgres user.

@hiyelbaz hiyelbaz closed this as completed Dec 3, 2020
@mkgrgis
Copy link
Contributor

mkgrgis commented Feb 4, 2023

@hiyelbaz , Your issue gives great idea for my PR #59, thanks!

@mkgrgis
Copy link
Contributor

mkgrgis commented Jun 28, 2024

@hiyelbaz , full read-only mode implemented in #78. Thanks for idea.

@hiyelbaz
Copy link
Author

@hiyelbaz , full read-only mode implemented in #78. Thanks for idea.

A bit late but wow super cool!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants