Windows用户Heroku pg:psql执行SELECT命令报错:'more'未被识别
heroku pg:psql on Windows Hey there! I’ve run into this exact issue before on Windows, so let’s get it sorted quickly. Here’s why it’s happening and how to fix it:
Why This Happens
When you run heroku pg:psql, the PostgreSQL client (psql) tries to use a pager to display long query results. By default, it might be pointing to the Unix-style more command, which doesn’t exist natively in Windows’ CMD or PowerShell—hence the error.
Quick Temporary Fix
If you just want to get past this right now, turn off the pager directly in your psql session:
- Once you’re connected to the Heroku database via
heroku pg:psql, run this command:\pset pager off - Now try your
SELECTquery again—it should output results without triggering the error.
Permanent Solutions
To avoid dealing with this every time you connect, pick one of these options:
Option 1: Disable Pager by Default for psql
- Create or edit the psql configuration file:
- In Windows, this file lives at
%APPDATA%\postgresql\psqlrc.conf(if it doesn’t exist, make a new text file with that exact name).
- In Windows, this file lives at
- Add this line to the file and save it:
\pset pager off - Next time you launch
heroku pg:psql, the pager will be disabled automatically.
Option 2: Use Windows’ Native Pager
If you still want pagination, tell psql to use Windows’ built-in more.com instead of the Unix more:
- Open the same
psqlrc.conffile mentioned above. - Add this line instead:
\set PAGER 'more.com' - Save the file—now psql will use the Windows-compatible pager when displaying long results.
Option 3: Fix the PAGER Environment Variable
Sometimes your system’s PAGER environment variable is set to more, which confuses psql:
- Temporary fix (for current session):
- In CMD: Run
set PAGER=more.com - In PowerShell: Run
$env:PAGER = 'more.com'
- In CMD: Run
- Permanent fix:
- Open System Properties → Advanced → Environment Variables
- Under "User Variables", find or create a
PAGERvariable and set its value tomore.com - Restart your terminal for the change to take effect
Final Check
After setting any of these up, launch heroku pg:psql again and run your SELECT query—you shouldn’t see that error anymore.
内容的提问来源于stack exchange,提问作者thox

