2

I am trying to get django running on an ubuntu 12.04 release using postgres (clean install). To get it running it used to be that you would have to edit the /etc/postgresql/9.1/main/pg_hba.conf file. However when I look at this release there is no /etc/postgresql directory only /etc/postgresql-common and there doesn't appear to be a file that resembles pg_hba.conf under that directory.

Additionally while I have you ear this is the change I wanted to make:

# change 
local   all         all                               ident
# to
local   all         all                               trust

is this correct, I think I saw that it should be changed to peer (not trust), if correct, why?

Update: This is the version of postgres

psql (PostgreSQL) 9.1.3

5 Answers 5

4

It turns out that postgres has an error during installation on the AWS version of ubuntu 12.04 I was getting a whole lot of these warnings

locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_MESSAGES to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory

Which when postgres tries to install

Error: The locale requested by the environment is invalid.
Error: could not create default cluster. Please create it manually with

    pg_createcluster 9.1 main --start

or a similar command (see 'man pg_createcluster').

So I found this link, Perl warning Setting locale failed unter Debian, which suggest setting the appropriate environment variables. Once set and the pg_createcluster command is run the postgres server was up and running.

1
  • I had this same issue last week. Some additional info, as it appears the current package version (postgresql-9.1=9.1.9-0ubuntu12.04) doesn't even show the error messages. I had Same symptoms as question, /etc/postgresql/<version> didn't exist neither did /var/lib/postgresql/<version>, but package reported as installed. I wound up installing the next previous version (9.1.3) which did show the error messages, but even with that I had to manually initialize the database and generate a server.crt. Fixing the locale and encoding environment variables would have been easier.
    – Jeremy
    Apr 14, 2013 at 22:17
1

From the description it looks like the server package, is not installed.

You should run:

sudo apt-get install postgresql-9.1
4
  • I had a check and yes it is installed (I ran your command), besides I thought that sudo apt-get install postgresql should pick up the most up to date version regardless of number Apr 29, 2012 at 23:05
  • If the postgresql-9.1 package is installed and /etc/postgresql has not been created, something must have went wrong during its installation. Is there also no /var/log/postgresql directory containing log files? Also no /var/lib/postgresql/9.1 (data directory)? Apr 30, 2012 at 1:44
  • Yes you were correct, postgres did not install properly, I'll detail my fix above Apr 30, 2012 at 4:53
  • Oh and thanks for the advice, sometimes you get a little too close to a problem to see how to fix it. Apr 30, 2012 at 5:05
1

Try removing postgresql completely

sudo apt-get purge postgresql postgresql-*

Check that you installed the locale files, which sometimes gives errors on Ubuntu server

sudo apt-get install language-pack-en-base

(replace en with your language's code)

Now install postgresql once more and check that there aren't any errors in the output

sudo apt-get install postgresql-9.1
1
  • Thanks! This fixed my issues on an EC2 default ubuntu 12.04 instance.
    – Geoff
    Jul 6, 2012 at 6:36
0

Are you trying to set up a db and user for django? If it's like Debian you want to su to postgres from root and then createuser and createb from there.

5
  • Yeah, I have done all that, my setup was all working on the 11.04 version of ubuntu (I added the user and the db, and that part still works) it just connecting django through to the postgres database isn't working the same way. Bare in mind if you do an upgrade of ubuntu the old will be there and working, it is in the clean install I am getting problems
    – Douglas Kastle
    Apr 29, 2012 at 12:49
  • Hm, I think that being more specific about the "isn't working" bit would go a long way to making me understand the problem. :)
    – JosefAssad
    Apr 29, 2012 at 13:06
  • Sorry dude not one of my more descriptive bug reports. What i was trying to say is that I can't find the pg_hba.conf file to edit, that's it. As a result I can't make the changes I know I need to make to make postgres work with django (that I know, which is probably not a lot), again bare in mine it is in a clean install, I have upgraded machines that still work.
    – Douglas Kastle
    Apr 29, 2012 at 13:12
  • OK. :) I don't think that the pg_hba.conf needs changing because of an ubuntu upgrade, but still, if that's your question then whenever you're looking for a file just locate filename in a terminal. Assumes you are diligently running updatedb. Both commands have pretty informative manpages.
    – JosefAssad
    Apr 29, 2012 at 13:17
  • I tried to do a recursive find of pg_hba.conf from /etc down, no luck, but I think that was a waste of time because there is no /etc/postgresql directory any more, just /etc/postgresql-common I ran updatedb it worked fine but didn't give me any information I could use.
    – Douglas Kastle
    Apr 29, 2012 at 13:24
0

If you have postgres running you can find its base directory like this:

$ ps aux | grep postmaster
postgres  1167  0.0  0.0  53764   536 ?        S    Mar29   0:33 /opt/postgres/bin/postmaster -D /data/db/postgres

(in my case postgres's base directory is /data/db/postgres YMMV)

9
  • Ok that is begining to make sense a little bit. I try to add a user, and is asks for for a password twice and then asks me if I want to make that user an admin, to which I say yes (all as sudo) but at the end it complains createuser: could not connect to database postgres: could not connect to server: No such file or directory I'm not too sure what's happening here any more, like a broken record, it is a clean install this used to work.
    – Douglas Kastle
    Apr 29, 2012 at 13:43
  • If it's running, you should be able to find it. If it's not running you should first start it, obviously. The other way would be to look in /etc/init.d/post* and see what that does. (I installed pg from source and I don't know how the ubuntu vanilla version is configured and packaged) Packages sometimes make weird choices about location of configfiles and data directories (brr: /var ... )
    – wildplasser
    Apr 29, 2012 at 13:49
  • Oh and in answer to your question this is what I get where I run your command ubuntu 13778 0.0 0.1 8068 652 pts/0 S+ 13:47 0:00 grep --color=auto postmaster seems to suggest that psostgres isn't even running, but I have run the commands sudo /etc/init.d/postgresql start and sudo /etc/init.d/postgresql restart withe no complaint (and no comments, positive or negative) but still not running as a result
    – Douglas Kastle
    Apr 29, 2012 at 13:49
  • Yes, the problem seems to relate to the fact that postgres is not running, even though all the hooks for setup suggest that it should be, and doesn't actually complain when it is failing
    – Douglas Kastle
    Apr 29, 2012 at 13:55
  • Still stuck though
    – Douglas Kastle
    Apr 29, 2012 at 14:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .