Socket File “/var/pgsql_socket/.s.PGSQL.5432” Missing In Mountain Lion (OS X Server)

后端 未结 20 2080
时光说笑
时光说笑 2020-12-12 09:48

I just upgraded my MacMini Server from Lion Server to Mountain Lion using OS X Server. I am having the same problem with PostgreSQL that I did last year when I first instal

相关标签:
20条回答
  • 2020-12-12 10:29

    Check for the status of the database:

    service postgresql status
    

    If the database is not running, start the db:

    sudo service postgresql start
    
    0 讨论(0)
  • 2020-12-12 10:30

    I was able to solve by simply filling in 127.0.0.1 for the PostgreSQL host address rather than leaving it blank. (Django Example)

    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.postgresql_psycopg2',
            'NAME': 'database_name',
            'USER': 'database_user',
            'PASSWORD': 'pass',
            'HOST': '127.0.0.1',
            'PORT': '',
            }
    }
    
    0 讨论(0)
  • 2020-12-12 10:33

    As mentioned by others in the comments, a really simple solution to this issue is to declare the database 'host' within the database configuration. Adding this answer just to make it a little more clear for anyone reading this.

    In a Ruby on Rails app for example, edit /config/database.yml:

    development:
      adapter: postgresql
      encoding: unicode
      database: database_name
      pool: 5
      host: localhost
    

    Note: the last line added to specify the host. Prior to updating to Yosemite I never needed to specify the host in this way.

    Hope this helps someone.

    Cheers

    0 讨论(0)
  • 2020-12-12 10:34

    check the postgres server is running with following code

    sudo service postgresql status
    

    if the postgres server is inactive, write the following command.

    sudo service postgresql start
    
    0 讨论(0)
  • 2020-12-12 10:35

    I was able to add the following to my .bash_profile to prevent the error:

    export PGHOST=localhost
    

    This works because:

    If you omit the host name, psql will connect via a Unix-domain socket to a server on the local host, or via TCP/IP to localhost on machines that don't have Unix-domain sockets.

    Your OS supports Unix domain sockets, but PostgreSQL's Unix socket that psql needs either doesn't exist or is in a different location than it expects.

    Specifying a hostname explicitly as localhost forces psql to use TCP/IP. Setting an environment variable PGHOST is one of the ways to achieve that. It's documented in psql's manual.

    0 讨论(0)
  • 2020-12-12 10:37

    If you have the above problem but you have upgraded from Yosemite, then a different approach is needed as the upgrade solution can destroy some files. More details are at `pg_tblspc` missing after installation of latest version of OS X (Yosemite or El Capitan).

    0 讨论(0)
提交回复
热议问题