Hacker News new | ask | show | jobs
by thewhitetulip 3839 days ago
I have read so much about postgres as a database, but sadly I have never been able to actually download install and use it, have read many tutorials but unfortunately it isn't as simple as installing mysql
9 comments

I can only assume that you are not using any mainstream *nix-based operating system. Installing through package management is easy for both MySQL and PostgreSQL.
I am using elementary OS and I have installed it many times, can you give me a good tutorial about installing and configuring postgres? I want to use it with golang for development of webapps. I am not trolling here btw, I am really stuck with sqlite because of inability of installing postgrest :(
I mean, with Gentoo Linux I had to do the following things:

* If I wanted to make Postgres listen on non-localhost, modify listen_addresses in postgresql.conf.

* Add database access controls as required in pg_hba.conf. The comments in the file are illuminating, but one can examine [0] for more information. [1]

* Create a database with appropriate permissions, along with a user. [2]

* Start Postgres.

I remember having to do the equivalent of all of those things every time I had to install MySQL. :)

What -exactly- did you successfully do, what -exactly- did you fail to do? Divulging that information will help guide assistance efforts. :)

[0] http://www.postgresql.org/docs/9.4/static/auth-pg-hba-conf.h...

[1] For example, the following line would allow password-based access from IPv4 localhost by the user "user" to the database "database":

  host database user 127.0.0.1/32 md5
[2] http://www.postgresql.org/docs/9.4/static/sql-createdatabase... for CREATE DATABASE syntax (or you can use createdb http://www.postgresql.org/docs/9.4/static/app-createdb.html ) http://www.postgresql.org/docs/9.4/static/sql-createrole.htm... for CREATE ROLE syntax (or you can use http://www.postgresql.org/docs/9.4/static/app-createuser.htm... ) http://www.postgresql.org/docs/9.4/static/sql-grant.html for GRANT syntax.
Hey,

I use elementary OS and all I did was sudo apt-get install postgres

I have no idea what it installed and what it didn't, in the entire process never once it asked me for a password and while connecting to the database it says that invalid password and I can't reset password without connecting to the database!! May I know your email ID? so I'll try to install it once and tell you how it goes.

As of now I have everything installed plus the graphical client with the elephant logo, but I just have no idea what the password is

> ...the entire process never once it asked me for a password and while connecting to the database it says that invalid password and I can't reset password without connecting to the database!!

Well, because you have access to the file that causes Postgres to determine whether or not you need to provide a password to access a given database (pg_hba.conf), you could simply change the authentication method to one that doesn't ask for a password. :)

However. On every Postgres install I've ever used, there are the following lines in pg_hba.conf:

  # "local" is for Unix domain socket connections only
  local   all all trust
If we look carefully, we see that the Type, Database, User, and Method entries are present, but the Address entry is not. The comment also talks about a Unix domain socket connection.

Reading the "Connecting to a Database" section of the manual for psql [0] (the official command-line Postgres client) tells us that if we omit the hostname, psql attempts to connect over the Unix domain socket. So, try the following things:

* psql

When that fails, because 'role "$MY_USERNAME" does not exist', try

* psql -U $DATABASE_USER

(The Postgresql database user is typically postgres.) If that fails for some other reason, try

* sudo su - $DATABASE_USER

* psql

You should now be connected to Postgres.

If we enter help , we see that we can enter "\?" for help with psql commands. If we enter \? and look through the list of commands, we should see one that does exactly the thing that we're trying to accomplish.

Anyway, leave a message here to let me know how this all went, or to ask any follow up questions.

[0] http://www.postgresql.org/docs/9.4/static/app-psql.html

Hey man, thank you very much, I was somehow able to connect to the psql database :) i created a user, a database and successfully created and dropped a table!

HN these days is full of elitist people who think the people who are struggling with things are downright dumb, hence the multiple downvotes I got on the earlier comment. It is because of people like you, my friend, that HN is still a user friendly community :)

Thank you!!

I'll check this out tonight
There are easy one-or-two-click installers for Windows and Mac OS X as well.
It is as simple, it's just not the same.

It's also in most distro and bsd repos.

For the benefits of PostgreSQL over MySQL it is definitely worth learning.

I'd love to hear what issues you're facing (if you can remember any specifics). Its been a long time since I first installed PostgreSQL, but I also recall some difficulties. Some things have improved since (eg. it's no longer necessary to change shared memory kernel parameters) but some things are still pretty difficult (eg. correctly configuring pg_hba.conf).

Other things are just confusing to newcomers (eg. different meanings of the term "database" between MySQL and Postgres, or understanding schemas and search_path).

Hey, I installed it via the available things on ubuntu software center, I have the graphical utility installed but when I try to connect to it, it says invalid password and I have no idea what the default password is since it didnt ask me
Have you created a user? If you don't create a user, and aren't acting as the postgres user, how do you expect to connect?
Sadly though I have no idea how to do that, can you direct me to some easy to understand installation guide?
Windows has an msi that also installs pgadmin and sets it up as a service, nothing could be simpler
What is your system? Installing it on OSX is super easy. Either using Homebrew or http://postgresapp.com
Elementary OS
It's easy on any major OS. Windows and OS X have one/two-click installers, Linux distros and BSDs pre-package it. The only really difficult case is a less-mainstream OS where you'll have to compile it, which honestly isn't that hard either.
Try running it inside docker: https://hub.docker.com/_/postgres/

I find that to be the easiest way to get up and running with it.

Have you asked a friend for help?
They already used "phone a friend" when they installed Python, so this time they are trying "ask the audience"; I can't wait to see them try and use "50/50" to install nginx.
Really? On OSX it's as simple as downloading postgres.app and dropping it in your applications folder. Couldn't be easier.
I don't use OSX I use elementary OS and I installed everything but it says incorrect password and I have no damn clue what the default password is because while installation it didn't ask me for a password!
What documentation or tutorial were you following? The first thing you need to do is create a user (or act as the postgres user on your os) and if the doc or tutorial was an official one, it should be made more clear and you should file a bug, if it wasn't then you should contact the owner and tell them their tutorial isn't clear.
https://help.ubuntu.com/community/PostgreSQL

I got all the help from this thread and the above link!