pgspider / sqlite_fdw

SQLite Foreign Data Wrapper for PostgreSQL
Other
212 stars 37 forks source link

Read-only mode #34

Closed hiyelbaz closed 3 years ago

hiyelbaz commented 3 years ago

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

hrkuma commented 3 years ago

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 commented 3 years ago

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.

mkgrgis commented 1 year ago

@hiyelbaz , Your issue gives great idea for my PR https://github.com/pgspider/sqlite_fdw/pull/59, thanks!

mkgrgis commented 2 months ago

@hiyelbaz , full read-only mode implemented in https://github.com/pgspider/sqlite_fdw/pull/78. Thanks for idea.