升级Sails至1.0后PostgreSQL数据库连接配置问题求助
Hey there, let's tackle this PostgreSQL connection problem you're facing after upgrading to Sails 1.0. Since you've already sorted out other errors, let's focus on getting that database link working.
First, here's your current datastore configuration formatted clearly:
module.exports.datastores = { localDiskDb: { adapter: 'sails-disk' }, postgreSql: { adapter: 'sails-postgresql', // url: 'postgresql://admin:root@localhost:5432/testdb', // ssl: true, host: 'localhost', user: 'admin', password: 'root', database: 'testdb' }, };
From the error screenshot you shared (showing connection-related failures), let's walk through common fixes step by step:
Verify PostgreSQL is running and reachable
Make sure your PostgreSQL service is up and listening on port 5432. On Linux/macOS, run these commands to check:# Check if PostgreSQL process is running ps aux | grep postgres # Check if port 5432 is open netstat -an | grep 5432On Windows, check the Services list for "postgresql-x64-XX" (XX is your version) and ensure it's started.
Validate database credentials and permissions
Log into PostgreSQL directly using your credentials to confirm they work:psql -U admin -d testdbIf this fails, you may need to create the user or grant proper permissions:
-- Create the user if it doesn't exist CREATE USER admin WITH PASSWORD 'root'; -- Grant full access to the testdb database GRANT ALL PRIVILEGES ON DATABASE testdb TO admin;Check PostgreSQL's authentication config (pg_hba.conf)
Thepg_hba.conffile controls how clients can authenticate. Locate this file (usually in your PostgreSQL data directory) and ensure there's a rule allowing your admin user to connect locally with password authentication:# Allow local connections for admin using md5 password local all admin md5 # Or for TCP/IP connections host all admin 127.0.0.1/32 md5After modifying this file, restart your PostgreSQL service for changes to take effect.
Try using the URL connection format
Sometimes using the consolidatedurlparameter instead of individual fields can resolve parsing issues. Uncomment theurlline and comment out the separatehost,user,password, anddatabaselines:postgreSql: { adapter: 'sails-postgresql', url: 'postgresql://admin:root@localhost:5432/testdb', // ssl: true, // host: 'localhost', // user: 'admin', // password: 'root', // database: 'testdb' },Ensure adapter compatibility
Double-check that yoursails-postgresqladapter version is compatible with Sails 1.0. Update to the latest compatible version if needed:npm install sails-postgresql@latest --save
Give these steps a try and let us know if any of them resolve the issue, or if you run into specific error messages we can dive deeper into!
内容的提问来源于stack exchange,提问作者Farhan Chauhan

