When to use pragmas on sqlite?

Sein Kraft picture Sein Kraft · May 21, 2010 · Viewed 10.1k times · Source

When the pragmas are used?

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

Answer

ax. picture ax. · May 21, 2010

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).