initdb: error: directory "/usr/local/var/postgres"exists but is not empty

개요



zauberware/rails-devise-graphql 을 사용하려고 처음으로 mac에 postgres를 넣은 로그입니다.

환경


  • macOS Mojave v10.14.6
  • pg_ctl (PostgreSQL) 13.1

  • 현상


    $ initdb /usr/local/var/postgres -E utf8
    The files belonging to this database system will be owned by user "gremito".
    This user must also own the server process.
    
    The database cluster will be initialized with locale "ja_JP.UTF-8".
    initdb: could not find suitable text search configuration for locale "ja_JP.UTF-8"
    The default text search configuration will be set to "simple".
    
    Data page checksums are disabled.
    
    initdb: error: directory "/usr/local/var/postgres" exists but is not empty
    If you want to create a new database system, either remove or empty
    the directory "/usr/local/var/postgres" or run initdb
    with an argument other than "/usr/local/var/postgres".
    

    해결


    $ rm -fr /usr/local/var/postgres
    
    $ brew services restart postgresql
    Stopping `postgresql`... (might take a while)
    ==> Successfully stopped `postgresql` (label: homebrew.mxcl.postgresql)
    ==> Successfully started `postgresql` (label: homebrew.mxcl.postgresql)
    
    $ initdb /usr/local/var/postgres -E utf8
    The files belonging to this database system will be owned by user "gremito".
    This user must also own the server process.
    
    The database cluster will be initialized with locale "ja_JP.UTF-8".
    initdb: could not find suitable text search configuration for locale "ja_JP.UTF-8"
    The default text search configuration will be set to "simple".
    
    Data page checksums are disabled.
    
    creating directory /usr/local/var/postgres ... ok
    creating subdirectories ... ok
    selecting dynamic shared memory implementation ... posix
    selecting default max_connections ... 100
    selecting default shared_buffers ... 128MB
    selecting default time zone ... Asia/Tokyo
    creating configuration files ... ok
    running bootstrap script ... ok
    performing post-bootstrap initialization ... ok
    syncing data to disk ... ok
    
    initdb: warning: enabling "trust" authentication for local connections
    You can change this by editing pg_hba.conf or using the option -A, or
    --auth-local and --auth-host, the next time you run initdb.
    
    Success. You can now start the database server using:
    
        pg_ctl -D /usr/local/var/postgres -l logfile start
    

    확인


    $ pg_ctl -D /usr/local/var/postgres -l logfile start
    pg_ctl: another server might be running; trying to start server anyway
    waiting for server to start.... stopped waiting
    pg_ctl: could not start server
    Examine the log output.
    
    $ brew services stop postgresql
    Stopping `postgresql`... (might take a while)
    ==> Successfully stopped `postgresql` (label: homebrew.mxcl.postgresql)
    
    $ pg_ctl -D /usr/local/var/postgres -l logfile start
    waiting for server to start.... done
    server started
    

    rake db


    config/database.yml 설정 후 다음 확인
    $ rake db:create
    Created database 'rails_devise_graphql_development'
    Created database 'db/rails_devise_graphql_test'
    
    $ rake db:migrate
    == 20190209162712 EnableExtensionForUuid: migrating ===========================
    -- extension_enabled?("pgcrypto")
       -> 0.0556s
    -- enable_extension("pgcrypto")
       -> 0.0236s
    == 20190209162712 EnableExtensionForUuid: migrated (0.0793s) ==================
    
    == 20190209163712 DeviseCreateUsers: migrating ================================
    -- create_table(:users, {:id=>:uuid})
       -> 0.0188s
    -- add_index(:users, :email, {:unique=>true})
       -> 0.0084s
    -- add_index(:users, :reset_password_token, {:unique=>true})
       -> 0.0050s
    -- add_index(:users, :confirmation_token, {:unique=>true})
       -> 0.0036s
    -- add_index(:users, :unlock_token, {:unique=>true})
       -> 0.0039s
    -- add_index("users", ["refresh_token"], {:name=>"index_users_on_refresh_token", :unique=>true, :using=>:btree})
       -> 0.0051s
    == 20190209163712 DeviseCreateUsers: migrated (0.0451s) =======================
    
    == 20200911092211 CreateActiveStorageTables: migrating ========================
    -- create_table(:active_storage_blobs)
       -> 0.0176s
    -- create_table(:active_storage_attachments)
       -> 0.0232s
    == 20200911092211 CreateActiveStorageTables: migrated (0.0410s) ===============
    
    == 20200912120337 CreateCompanies: migrating ==================================
    -- create_table(:companies, {:id=>:uuid})
       -> 0.0105s
    == 20200912120337 CreateCompanies: migrated (0.0106s) =========================
    
    == 20200912153138 AddSlugToCompanies: migrating ===============================
    -- add_column(:companies, :slug, :string)
       -> 0.0027s
    -- add_index(:companies, :slug, {:unique=>true})
       -> 0.0036s
    == 20200912153138 AddSlugToCompanies: migrated (0.0065s) ======================
    
    == 20200912153858 CreateFriendlyIdSlugs: migrating ============================
    -- create_table(:friendly_id_slugs)
       -> 0.0084s
    -- add_index(:friendly_id_slugs, :sluggable_id)
       -> 0.0056s
    -- add_index(:friendly_id_slugs, [:slug, :sluggable_type])
       -> 0.0060s
    -- add_index(:friendly_id_slugs, [:slug, :sluggable_type, :scope], {:unique=>true})
       -> 0.0036s
    -- add_index(:friendly_id_slugs, :sluggable_type)
       -> 0.0034s
    == 20200912153858 CreateFriendlyIdSlugs: migrated (0.0359s) ===================
    
    == 20200920102035 DeviseInvitableAddToUsers: migrating ========================
    -- change_table(:users)
       -> 0.0442s
    == 20200920102035 DeviseInvitableAddToUsers: migrated (0.0443s) ===============
    
    Annotated (3): app/models/user.rb, spec/models/user_spec.rb, spec/factories/users.rb
    
    $ rake db:seed
    
    



    PSequel 에서 정상적으로 DB와 테이블이 만들어졌기 때문에 끝.

    참고 기사


  • macOS에 PostgreSQL 설치
  • MacOS Catalina에서 Postgresql 설치 및 초기 작업

  •  

    좋은 웹페이지 즐겨찾기