postgresql dblink_connect timeout

时间:2016-05-31 03:14:09

标签: postgresql

我正在尝试使用dblink将数据从一个系统移动到另一个系统。这两台机器都是RHEL 5.11,两者都运行postgresql 9.2,两者都在公司内部网络上,它们之间没有防火墙规则。我正在从我的桌面vpn进入公司内部网络。

调用两台计算机FROMTO。 FROM机器安装了dblink作为扩展,TO机器没有。对于这两台机器,我指定的用户都有一个pg_hba.conf主机条目,列出了all表示数据库,0.0.0.0/0表示地址,trust

使用pgadmin3,我可以从桌面连接到这两台计算机,在两者上查看/添加/修改数据库。我认为这可以排除琐碎的连接问题和权限作为问题的潜在来源。

pgadmin计算机的FROM查询窗口中,我执行此操作:

SELECT dblink_connect('AAA','host=TO dbname=XXX user=postgres password=ZZZ');

-OR -

SELECT dblink_connect('host=TO dbname=XXX user=postgres password=ZZZ');

-OR -

psql计算机的FROM命令行输入上述任何一种。

在消息窗格或命令行中传递此消息的结果:

  

-----错误:无法建立连接DETAIL:无法连接到服务器:连接超时服务器是否在主机上运行   "至" (AAA.BBB.CCC.DDD)并接受端口5432上的TCP / IP连接?

     

**********错误**********

     

错误:无法建立连接SQL状态:08001

     

详细信息:无法连接到服务器:连接超时是   服务器在主机上运行" TO" (AAA.BBB.CCC.DDD)并接受TCP / IP

     端口5432上的

连接?

建议?

更新 - 尝试更换主机名" TO"使用" localhost",结果相同。 - 但是,dblink_connect(' dbname_on_FROM');作品。所以基本的dblink功能正在发挥作用。 - 原始问题仍未解决,因为我想将数据发送到TO机器上的服务器。

1 个答案:

答案 0 :(得分:0)

我不确定你是否能够找出问题,但无论如何我都会回答。 &#34; TO&#34;机器的数据库可能在不同于5432的import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v7.app.AlertDialog; import android.support.v7.widget.GridLayoutManager; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.util.AttributeSet; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.EditText; import com.melnykov.fab.FloatingActionButton; import com.safir.dreamreminder.Activity.MainActivity; import com.safir.dreamreminder.R; import com.safir.dreamreminder.dataBase.DataBaseHandler2; import com.safir.dreamreminder.dataBase.Data_Dream; import java.util.List; public class BigDream extends Fragment { public DataBaseHandler2 db; RecyclerView mRecycleView; RecyclerView.LayoutManager mLayoutManager; RecyclerView.Adapter mAdapter; private FloatingActionButton fab; public BigDream() { // Required empty public constructor } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment DataBaseHandler2 dbb = new DataBaseHandler2(getActivity()); Log.d("Reading: ", "Reading all contacts.."); List<Data_Dream> contacts = dbb.getAllContactss(); for (Data_Dream cn : contacts) { GridAdapter.dat.add(cn.getDream()); String log = "Dream: " + cn.getDream() ; // Writing Contacts to log Log.d("Name: ", log); } View rootview=inflater.inflate(R.layout.recycler_view_frag, container, false); mRecycleView=(RecyclerView) rootview.findViewById(R.id.recyclerView); mRecycleView.setHasFixedSize(true); mLayoutManager=new LinearLayoutManager(getActivity()); mRecycleView.setLayoutManager(mLayoutManager); mAdapter=new GridAdapter(); mRecycleView.setAdapter(mAdapter); fab = (FloatingActionButton) rootview.findViewById(R.id.fab); fab.attachToRecyclerView( mRecycleView); fab.show(); fab.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getActivity()); LayoutInflater inflater = getActivity().getLayoutInflater(); final View dialogView = inflater.inflate(R.layout.edit_item, null); dialogBuilder.setView(dialogView); final EditText edt = (EditText) dialogView.findViewById(R.id.title); final EditText editt = (EditText) dialogView.findViewById(R.id.detaill); dialogBuilder.setPositiveButton("Done", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { db = new DataBaseHandler2(getActivity()); String step = edt.getText().toString(); String detail = editt.getText().toString(); /** * CRUD Operations * */ // Inserting Contacts Log.d("Insert: ", "Inserting .."); db.addContactss(new Data_Dream(step, detail)); Intent be = new Intent(getActivity(), MainActivity.class); getActivity().finishAffinity(); startActivity(be); } }); dialogBuilder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { //pass } }); AlertDialog b = dialogBuilder.create(); b.show(); } } ); return rootview; } private static class NpaGridLayoutManager extends GridLayoutManager { /** * Disable predictive animations. There is a bug in RecyclerView which causes views that * are being reloaded to pull invalid ViewHolders from the internal recycler stack if the * adapter size has decreased since the ViewHolder was recycled. */ @Override public boolean supportsPredictiveItemAnimations() { return false; } public NpaGridLayoutManager(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); } public NpaGridLayoutManager(Context context, int spanCount) { super(context, spanCount); } public NpaGridLayoutManager(Context context, int spanCount, int orientation, boolean reverseLayout) { super(context, spanCount, orientation, reverseLayout); } } } import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.support.v7.app.AlertDialog; import android.support.v7.widget.GridLayoutManager; import android.support.v7.widget.RecyclerView; import android.util.AttributeSet; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.TextView; //import com.example.android.navigationdrawerexample.R; import com.safir.dreamreminder.Activity.MainActivity; import com.safir.dreamreminder.R; import com.safir.dreamreminder.dataBase.DataBaseHandler2; import com.safir.dreamreminder.dataBase.Data_Dream; import java.util.ArrayList; import java.util.List; /** * Created by ooyanetomohito on 6/22/15. */ public class GridAdapter extends RecyclerView.Adapter<GridAdapter.ViewHolder> { public static Context bee; public static DataBaseHandler2 be; public static ArrayList<String> dat=new ArrayList<String>(); public static ArrayList<String> del=new ArrayList<String>(); List<item> mItems; public GridAdapter() { mItems = new ArrayList<item>(); for(int i=0;i<dat.size();i++){ item species = new item(); species.setDream(dat.get(i)); species.setImg(R.mipmap.startup); mItems.add(species); // notifyDataSetChanged(); } } class ViewHolder extends RecyclerView.ViewHolder{ public ImageView mThumbnail; public TextView tvspecies; public ViewHolder(View itemView) { super(itemView); // notifyDataSetChanged(); bee=itemView.getContext(); itemView.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { be = new DataBaseHandler2(bee); // be.deleteContact(new Data(RecyclerViewFragment.judul.get(getPosition()),RecyclerViewFragment.detail.get(getPosition()))); AlertDialog.Builder builder = new AlertDialog.Builder(v.getContext()); builder.setMessage("Delete this Dream?"); String positiveText = "ok"; builder.setPositiveButton(positiveText, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { be.deleteContact(new Data_Dream(GridAdapter.del.get(getPosition()))); Intent ha = new Intent(bee, MainActivity.class); ((MainActivity) bee).finishAffinity(); bee.startActivity(ha); } }); String negativeText = "cansel"; builder.setNegativeButton(negativeText, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // negative button logic } }); AlertDialog b = builder.create(); b.show(); return true; } }); DataBaseHandler2 db = new DataBaseHandler2(itemView.getContext()); Log.d("Reading: ", "Reading all contacts.."); List<Data_Dream> contacts = db.getAllContactss(); mItems = new ArrayList<item>(); for (Data_Dream cn : contacts) { item species = new item(); species.setDream(cn.getDream()); dat.add(cn.getDream()); species.setImg(R.mipmap.startup); mItems.add(species); String log = "Dream: " + cn.getDream() ; // Writing Contacts to log Log.d("Name: ", log); } mThumbnail = (ImageView)itemView.findViewById(R.id.thumbnail_img); tvspecies = (TextView)itemView.findViewById(R.id.bigDream); } } @Override public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) { View v = LayoutInflater.from(viewGroup.getContext()) .inflate(R.layout.grid_item, viewGroup, false); ViewHolder viewHolder = new ViewHolder(v); return viewHolder; } @Override public void onBindViewHolder(ViewHolder viewHolder, int i) { item nature = mItems.get(i); del.add(nature.getDream()); viewHolder.tvspecies.setText(nature.getDream()); viewHolder.mThumbnail.setImageResource(nature.getImg()); } @Override public int getItemCount() { return mItems.size(); } } 上运行。您需要确保运行数据库服务器的端口以及您在&#34; FROM&#34;中指定的端口。机器是相同

如果端口号相同,那么在&#34; FROM&#34;中指定这些参数时,porthostusername中必定存在错误。机。