diff --git a/pg_wrapper b/pg_wrapper
index 2de0c2531896b1be424276892f4ba922884a5238..2c41d14f54f27c103422cb14d26bb5e9520159e2 100755
--- a/pg_wrapper
+++ b/pg_wrapper
@@ -17,6 +17,8 @@
use strict;
+use POSIX;
+
use lib '/usr/share/postgresql-common';
use PgCommon;
@@ -100,7 +102,8 @@ my $cmd = get_program_path ($cmdname, $version);
# libreadline is a lot better than libedit, so prefer that
if ($cmdname eq 'psql') {
my @readlines;
- push @readlines, sort(</lib/*/libreadline.so.*>);
+ my $arch = (POSIX::uname)[4];
+ push @readlines, sort(</lib/$arch-*/libreadline.so.*>);
push @readlines, sort(</lib/libreadline.so.*>);
if (@readlines) {
$ENV{'LD_PRELOAD'} = ($ENV{'LD_PRELOAD'} or '') . ':' . $readlines[-1];