Skip to content

Instantly share code, notes, and snippets.

@knownasilya
Last active December 20, 2015 20:59
Show Gist options
  • Save knownasilya/6194744 to your computer and use it in GitHub Desktop.
Save knownasilya/6194744 to your computer and use it in GitHub Desktop.
psql user role
# Django settings for nycbb project.
from os import environ
from os.path import join, abspath, dirname
# Private settings
SECRET_KEY = environ["SECRET_KEY"]
DB_USER = environ["DB_USER"]
DB_PASSWORD = environ["DB_PASSWORD"]
# Defines the PROJECT_ROOT, used for relative settings elsewhere.
here = lambda *x: join(abspath(dirname(__file__)), *x)
PROJECT_ROOT = here('../..')
root = lambda *x: join(abspath(PROJECT_ROOT), *x)
DEBUG = True
TEMPLATE_DEBUG = DEBUG
ADMINS = (
# ('Your Name', '[email protected]'),
)
MANAGERS = ADMINS
DATABASES = {
'default': {
'ENGINE': 'django.contrib.gis.db.backends.postgis', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'nycbb', # Or path to database file if using sqlite3.
# The following settings are not used with sqlite3:
'USER': DB_USER,
'PASSWORD': DB_PASSWORD,
'HOST': 'localhost', # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
'PORT': '5432', # Set to empty string for default.
}
}
# Hosts/domain names that are valid for this site; required if DEBUG is False
# See https://docs.djangoproject.com/en/1.5/ref/settings/#allowed-hosts
ALLOWED_HOSTS = []
# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# In a Windows environment this must be set to your system time zone.
TIME_ZONE = 'America/Chicago'
# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'en-us'
SITE_ID = 1
# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True
# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale.
USE_L10N = True
# If you set this to False, Django will not use timezone-aware datetimes.
USE_TZ = True
# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/var/www/example.com/media/"
MEDIA_ROOT = root('media')
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://example.com/media/", "http://media.example.com/"
MEDIA_URL = '/media/'
# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/var/www/example.com/static/"
STATIC_ROOT = root('collected_static')
# URL prefix for static files.
# Example: "http://example.com/static/", "http://static.example.com/"
STATIC_URL = '/static/'
# Additional locations of static files
STATICFILES_DIRS = (
# Put strings here, like "/home/html/static" or "C:/www/django/static".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
root('static'),
)
# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
# Make this unique, and don't share it with anybody.
SECRET_KEY = SECRET_KEY
# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
# 'django.template.loaders.eggs.Loader',
)
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
# Uncomment the next line for simple clickjacking protection:
# 'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
ROOT_URLCONF = 'nycbb.urls'
# Python dotted path to the WSGI application used by Django's runserver.
WSGI_APPLICATION = 'nycbb.wsgi.application'
TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
root('templates'),
)
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
'django.contrib.admindocs',
# project
'buildings',
)
# A sample logging configuration. The only tangible logging
# performed by this configuration is to send an email to
# the site admins on every HTTP 500 error when DEBUG=False.
# See http://docs.djangoproject.com/en/dev/topics/logging for
# more details on how to customize your logging configuration.
LOGGING = {
'version': 1,
'disable_existing_loggers': True,
'formatters': {
'standard': {
'format' : "[%(asctime)s] %(levelname)s [%(name)s:%(lineno)s] %(message)s",
'datefmt' : "%d/%b/%Y %H:%M:%S"
},
},
'handlers': {
'null': {
'level':'DEBUG',
'class':'django.utils.log.NullHandler',
},
'logfile': {
'level':'DEBUG',
'class':'logging.handlers.RotatingFileHandler',
'filename': root('logfile.log'),
'maxBytes': 50000,
'backupCount': 2,
'formatter': 'standard',
},
'console':{
'level':'INFO',
'class':'logging.StreamHandler',
'formatter': 'standard'
},
},
'loggers': {
'django': {
'handlers':['console'],
'propagate': True,
'level':'WARN',
},
'django.db.backends': {
'handlers': ['console'],
'level': 'DEBUG',
'propagate': False,
},
'buildings': {
'handlers': ['console', 'logfile'],
'level': 'DEBUG',
},
}
}
File "/home/vagrant/.venvs/nycbb/local/lib/python2.7/site-packages/psycopg2/__
init__.py", line 164, in connect
conn = _connect(dsn, connection_factory=connection_factory, async=async)
" does not existonalError: FATAL: role "django
" does not exist: FATAL: role "django
2013-08-09 16:59:09 UTC LOG: database system is ready to accept connections
2013-08-09 16:59:09 UTC LOG: autovacuum launcher started
2013-08-09 16:59:10 UTC LOG: incomplete startup packet
2013-08-09 16:59:13 UTC LOG: received SIGHUP, reloading configuration files
2013-08-09 17:00:03 UTC ERROR: extension "plpgsql" already exists
2013-08-09 17:00:03 UTC STATEMENT: CREATE EXTENSION plpgsql WITH SCHEMA templat
e_postgis;
" does not exist:08 UTC FATAL: role "django
" does not exist:08 UTC FATAL: role "django
# Create a django database user for vagrant
# not superuser,can't create dbs, can't create roles
psql --username=postgres -c "CREATE USER django NOSUPERUSER NOCREATEDB NOCREATEROLE;"
psql --username=postgres -c "ALTER ROLE django WITH PASSWORD 'django';"
# Create a project database owned by the django user
psql --username=postgres -c "CREATE DATABASE nycbb OWNER django TEMPLATE template_postgis;"
postgres=# \du
List of roles
Role name | Attributes | Member of
-----------+------------------------------------------------+-----------
django | | {}
postgres | Superuser, Create role, Create DB, Replication | {}
postgres=# show port;
port
------
5432
(1 row)
# after running python manage.py syncdb
# notice no closing quote after django (a \r somewhere)
Traceback (most recent call last):
File "/vagrant/manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/vagrant/.venvs/nycbb/local/lib/python2.7/site-packages/django/core
/management/__init__.py", line 453, in execute_from_command_line
utility.execute()
File "/home/vagrant/.venvs/nycbb/local/lib/python2.7/site-packages/django/core
/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/vagrant/.venvs/nycbb/local/lib/python2.7/site-packages/django/core
/management/__init__.py", line 272, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/home/vagrant/.venvs/nycbb/local/lib/python2.7/site-packages/django/core
/management/__init__.py", line 77, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "/home/vagrant/.venvs/nycbb/local/lib/python2.7/site-packages/django/util
s/importlib.py", line 35, in import_module
__import__(name)
File "/home/vagrant/.venvs/nycbb/local/lib/python2.7/site-packages/south/manag
ement/commands/__init__.py", line 10, in <module>
import django.template.loaders.app_directories
File "/home/vagrant/.venvs/nycbb/local/lib/python2.7/site-packages/django/temp
late/loaders/app_directories.py", line 23, in <module>
mod = import_module(app)
File "/home/vagrant/.venvs/nycbb/local/lib/python2.7/site-packages/django/util
s/importlib.py", line 35, in import_module
__import__(name)
File "/home/vagrant/.venvs/nycbb/local/lib/python2.7/site-packages/django/cont
rib/admin/__init__.py", line 3, in <module>
from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME
File "/home/vagrant/.venvs/nycbb/local/lib/python2.7/site-packages/django/cont
rib/admin/helpers.py", line 4, in <module>
from django.contrib.admin.util import (flatten_fieldsets, lookup_field,
File "/home/vagrant/.venvs/nycbb/local/lib/python2.7/site-packages/django/cont
rib/admin/util.py", line 6, in <module>
from django.db import models
File "/home/vagrant/.venvs/nycbb/local/lib/python2.7/site-packages/django/db/_
_init__.py", line 40, in <module>
backend = load_backend(connection.settings_dict['ENGINE'])
File "/home/vagrant/.venvs/nycbb/local/lib/python2.7/site-packages/django/db/_
_init__.py", line 34, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/home/vagrant/.venvs/nycbb/local/lib/python2.7/site-packages/django/db/u
tils.py", line 94, in __getitem__
conn = backend.DatabaseWrapper(db, alias)
File "/home/vagrant/.venvs/nycbb/local/lib/python2.7/site-packages/django/cont
rib/gis/db/backends/postgis/base.py", line 11, in __init__
self.ops = PostGISOperations(self)
File "/home/vagrant/.venvs/nycbb/local/lib/python2.7/site-packages/django/cont
rib/gis/db/backends/postgis/operations.py", line 92, in __init__
vtup = self.postgis_version_tuple()
File "/home/vagrant/.venvs/nycbb/local/lib/python2.7/site-packages/django/cont
rib/gis/db/backends/postgis/operations.py", line 444, in postgis_version_tuple
version = self.postgis_lib_version()
File "/home/vagrant/.venvs/nycbb/local/lib/python2.7/site-packages/django/cont
rib/gis/db/backends/postgis/operations.py", line 424, in postgis_lib_version
return self._get_postgis_func('postgis_lib_version')
File "/home/vagrant/.venvs/nycbb/local/lib/python2.7/site-packages/django/cont
rib/gis/db/backends/postgis/operations.py", line 405, in _get_postgis_func
cursor = self.connection._cursor()
File "/home/vagrant/.venvs/nycbb/local/lib/python2.7/site-packages/django/db/b
ackends/postgresql_psycopg2/base.py", line 182, in _cursor
self.connection = Database.connect(**conn_params)
File "/home/vagrant/.venvs/nycbb/local/lib/python2.7/site-packages/psycopg2/__
init__.py", line 164, in connect
conn = _connect(dsn, connection_factory=connection_factory, async=async)
" does not existonalError: FATAL: role "django
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment