When to use pragmas on sqlite?

2019-04-06 22:46发布

问题:

When the pragmas are used?

When the database is created for first time or in each connection to database?

回答1:

this depends on the pragma being used. from The definitive guide to SQLite, Database Configuration:

Many pragmas have both temporary and permanent forms. Temporary forms affect only the current session for the duration of its lifetime. The permanent forms are stored in the database and affect every session.

or, in the words of your question: Temporary forms are used in each connection to database, permanent forms are used when the database is created for the first time.

the pragma documentation doesn't explicitly specify if a pragma is temporary or permanent. however, it usually says something like

auto-vacuuming must be turned on before any tables are created. It is not possible to enable or disable auto-vacuum after a table has been created.

meaning auto_vacuum is a permanent pragma, or

When you change the cache size using the cache_size pragma, the change only endures for the current session.

meaning cache_size is a temporary one.

so your best bet to answer your question is to carefully read the documentation for your specific pragma. alternatively, you can study the pragma source code (search for ** PRAGMA [, case sensitive).



标签: sqlite pragma