Unable to open database file

Asked by Mohan on 2012-03-30

/graphite/graphite-web-0.9.9/webapp/graphite$ sudo python manage.py syncdb throws and error

I have read 178172: OperationalError: unable to open database file (Solved) and follow http://geek.michaelgrace.org/2011/09...ite-on-ubuntu/

I thought there could be permissions issues in this folder /opt/graphite/storage/ but /opt/graphite/storage/graphite.db does not exist.

Should it be created automatically ? It is Ubuntu 11.10

File "/usr/lib/pymodules/python2.7/django/db/backends/sqlite3/base.py", line 207, in _cursor
    self.connection = Database.connect(**kwargs)
pysqlite2.dbapi2.OperationalError: unable to open database file

Thanks.

Question information

Language:
English Edit question
Status:
Solved
For:
Graphite Edit question
Assignee:
No assignee Edit question
Solved by:
Mohan
Solved:
2012-04-10
Last query:
2012-04-10
Last reply:
2012-04-06
cbrinley (cbrinley) said : #1

it should yes,
can you post your config around the database settings (settings.py) and
please verify the account running "syncdb" does have correct permissions.
other posts of this this kind have indicated either a permission issue or
pre-existing file.

thanks

On Fri, Mar 30, 2012 at 3:55 AM, Mohan <<email address hidden>
> wrote:

> New question #192127 on Graphite:
> https://answers.launchpad.net/graphite/+question/192127
>
> I have read 178172: OperationalError: unable to open database file
> (Solved) and follow http://geek.michaelgrace.org/2011/09...ite-on-ubuntu/
>
> I thought there could be permissions issues in this folder
> /opt/graphite/storage/ but /opt/graphite/storage/graphite.db does not exist.
>
> Should it be created automatically ? It is Ubuntu 11.10
>
> File "/usr/lib/pymodules/python2.7/django/db/backends/sqlite3/base.py",
> line 207, in _cursor
> self.connection = Database.connect(**kwargs)
> pysqlite2.dbapi2.OperationalError: unable to open database file
>
>
> Thanks.
>
> --
> You received this question notification because you are a member of
> graphite-dev, which is an answer contact for Graphite.
>
> _______________________________________________
> Mailing list: https://launchpad.net/~graphite-dev
> Post to : <email address hidden>
> Unsubscribe : https://launchpad.net/~graphite-dev
> More help : https://help.launchpad.net/ListHelp
>

--

Chris Brinley
Cleartrial

e: <email address hidden>
p: 312-460-3038
m: 219-789-2811

Mohan (radhakrishnan-mohan) said : #2

Hi,
              This part is unchanged. This directory tree can be read and written by the user calling 'syncdb'. Is there any other permission required ?

Nothing is changed in the original files.

Thanks.

# Filesystem layout (all directores should end in a /)
WEB_DIR = dirname( abspath(__file__) ) + '/'
WEBAPP_DIR = dirname( dirname(WEB_DIR) ) + '/'
GRAPHITE_ROOT = dirname( dirname(WEBAPP_DIR) ) + '/'
CONTENT_DIR = WEBAPP_DIR + 'content/'
CSS_DIR = CONTENT_DIR + 'css/'
THIRDPARTY_DIR = WEB_DIR + 'thirdparty/'

CONF_DIR = os.environ.get('GRAPHITE_CONF_DIR', GRAPHITE_ROOT + 'conf/')
STORAGE_DIR = os.environ.get('GRAPHITE_STORAGE_DIR', GRAPHITE_ROOT + 'storage/')
LISTS_DIR = STORAGE_DIR + 'lists/'
INDEX_FILE = STORAGE_DIR + 'index'
WHITELIST_FILE = LISTS_DIR + 'whitelist'
LOG_DIR = STORAGE_DIR + 'log/webapp/'

Mohan (radhakrishnan-mohan) said : #3

Status shows Answered. Updating with this comment.

cbrinley (cbrinley) said : #4

Hi mohan
I should have noticed this earlier. Since your using sudo permissions
should be fine. I don't see any db configuration in your post. Please
confirm you have a section in your config that looks like that referenced
in this doc:
https://docs.djangoproject.com/en/1.2/ref/settings/#databases

Also please verify your django version: (1.4 is not yet supported)
https://docs.djangoproject.com/en/dev/ref/django-admin/#determining-the-version
On Apr 2, 2012 12:36 AM, "Mohan" <email address hidden>
wrote:

> Question #192127 on Graphite changed:
> https://answers.launchpad.net/graphite/+question/192127
>
> Status: Answered => Open
>
> Mohan is still having a problem:
> Status shows Answered. Updating with this comment.
>
> --
> You received this question notification because you are a member of
> graphite-dev, which is an answer contact for Graphite.
>
> _______________________________________________
> Mailing list: https://launchpad.net/~graphite-dev
> Post to : <email address hidden>
> Unsubscribe : https://launchpad.net/~graphite-dev
> More help : https://help.launchpad.net/ListHelp
>

Mohan (radhakrishnan-mohan) said : #5

Ok. This is the section I just updated. I created db/nio.db. syncdb doesn't succeed though.

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqllite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': '/opt/graphite/storage/db/nio.db', # Or path to database file if using sqlite3.
        'USER': '', # Not used with sqlite3.
        'PASSWORD': '', # Not used with sqlite3.
        'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
        'PORT': '', # Set to empty string for default. Not used with sqlite3.
    }
}

'user' that is trying 'syncdb' has read/write permission to this folder 'db'. Does it have anything to do with the user 'www-data'

drwxrwxr-x 2 user user 4096 2012-04-02 22:28 db

Mohan (radhakrishnan-mohan) said : #6

The version of django is 1.3.

Mohan (radhakrishnan-mohan) said : #7

/usr/lib/pymodules/python2.7/django/conf/project_template/settings.py:DATABASES = {
/usr/lib/pymodules/python2.6/django/conf/project_template/settings.py:DATABASES = {
/usr/share/pyshared/django/conf/project_template/settings.py:DATABASES = {

Some more information. I am not using python2.6 because when I type 'python' I get the following prompt.

Python 2.7.2+ (default, Oct 4 2011, 20:03:08)
[GCC 4.6.1] on linux2

I have updated both the following files. Not sure which one is used though.

/usr/lib/pymodules/python2.7/django/conf/project_template/settings.py
/usr/share/pyshared/django/conf/project_template/settings.py

cbrinley (cbrinley) said : #8

Can fu try creating sqlite db directly from python shell in another dir.
Then in target dir and see what happens. Not sure you need to modify any
files outside of the graphite dir. I can't comment on affects without
looking at the change more closely.
On Apr 4, 2012 12:26 AM, "Mohan" <email address hidden>
wrote:

> Question #192127 on Graphite changed:
> https://answers.launchpad.net/graphite/+question/192127
>
> Mohan gave more information on the question:
> /usr/lib/pymodules/python2.7/django/conf/project_template/settings.py:DATABASES
> = {
> /usr/lib/pymodules/python2.6/django/conf/project_template/settings.py:DATABASES
> = {
> /usr/share/pyshared/django/conf/project_template/settings.py:DATABASES = {
>
> Some more information. I am not using python2.6 because when I type
> 'python' I get the following prompt.
>
>
> Python 2.7.2+ (default, Oct 4 2011, 20:03:08)
> [GCC 4.6.1] on linux2
>
> I have updated both the following files. Not sure which one is used
> though.
>
> /usr/lib/pymodules/python2.7/django/conf/project_template/settings.py
> /usr/share/pyshared/django/conf/project_template/settings.py
>
> --
> You received this question notification because you are a member of
> graphite-dev, which is an answer contact for Graphite.
>
> _______________________________________________
> Mailing list: https://launchpad.net/~graphite-dev
> Post to : <email address hidden>
> Unsubscribe : https://launchpad.net/~graphite-dev
> More help : https://help.launchpad.net/ListHelp
>

Mohan (radhakrishnan-mohan) said : #9

I am able to create a db in the target directory as well as in other directories. I created a db in the target directory and added a table and then tried to run syncdb. But unfortunately I got the same error.

Looks like there is a simple mistake somewhere.

Mohan (radhakrishnan-mohan) said : #10

Ok. Looks like I am not using the correct settings.py. The django users gave me a hint. Now I have specifically changed the settings.py in the graphite 'webapp' directory to an absolute path. It worked.

Thanks for your patience brinley.

As far as I know the variable GRAPHITE _STORAGE_DIR wasn't set anywhere. I used an absolute path /opt/graphite/storage/graphite.db instead of it in the settings.py

There are so many related questions in various forums.

cbrinley (cbrinley) said : #11

Ah ok, yea it wasn't adding up to me. Glad a solution was found.
Take care

On Tue, Apr 10, 2012 at 12:30 AM, Mohan <
<email address hidden>> wrote:

> Question #192127 on Graphite changed:
> https://answers.launchpad.net/graphite/+question/192127
>
> Status: Answered => Solved
>
> Mohan confirmed that the question is solved:
> Ok. Looks like I am not using the correct settings.py. The django users
> gave me a hint. Now I have specifically changed the settings.py in the
> graphite 'webapp' directory to an absolute path. It worked.
>
> Thanks for your patience brinley.
>
> As far as I know the variable GRAPHITE _STORAGE_DIR wasn't set anywhere.
> I used an absolute path /opt/graphite/storage/graphite.db instead of it
> in the settings.py
>
> There are so many related questions in various forums.
>
> --
> You received this question notification because you are a member of
> graphite-dev, which is an answer contact for Graphite.
>
> _______________________________________________
> Mailing list: https://launchpad.net/~graphite-dev
> Post to : <email address hidden>
> Unsubscribe : https://launchpad.net/~graphite-dev
> More help : https://help.launchpad.net/ListHelp
>

--

Chris Brinley
Cleartrial

e: <email address hidden>
p: 312-460-3038
m: 219-789-2811